Python交互式Shell适用于尝试和测试小型脚本代码,但不适用于大型项目。在实际工作环境中,开发人员使用不同的代码编辑器来编写代码。在这30天的Python编程挑战中,我们将使用Visual Studio Code。Visual Studio Code是一个非常流行的开源文本编辑器。我是vscode的粉丝,我建议下载Visual Studio Code,但如果您更喜欢其他编辑器,请随意使用您拥有的编辑器。
print('1 is 1',1is1)# True - 因为数据值相同
+print('1 is not 2',1isnot2)# True - 因为1不等于2
+print('A in Asabeneh','A'in'Asabeneh')# True - A在字符串中找到
+print('B in Asabeneh','B'in'Asabeneh')# False - 没有大写B
+print('coding'in'coding for all')# True - 因为coding for all包含单词coding
+print('a in an:','a'in'an')# True
+print('4 is 2 ** 2:',4is2**2)# True
+
letter='P'# 一个字符串可以是一个单字符或一堆文本
+print(letter)# P
+print(len(letter))# 1
+greeting='Hello, World!'# 字符串可以使用单引号或双引号创建,"Hello, World!"
+print(greeting)# Hello, World!
+print(len(greeting))# 13
+sentence="I hope you are enjoying 30 days of Python Challenge"
+print(sentence)
+
+
多行字符串可以使用三重单引号''''或三重双引号""""创建。请参考以下示例。
+
multiline_string='''I am a teacher and enjoy teaching.
+I didn't find anything as rewarding as empowering people.
+That is why I created 30 days of python.'''
+print(multiline_string)
+
+# 还有另一种做同样事情的方法
+multiline_string="""I am a teacher and enjoy teaching.
+I didn't find anything as rewarding as empowering people.
+That is why I created 30 days of python."""
+print(multiline_string)
+
# 仅包含字符串
+first_name='Asabeneh'
+last_name='Yetayeh'
+language='Python'
+formated_string='I am %s%s. I teach %s'%(first_name,last_name,language)
+print(formated_string)
+
+# 包含字符串和数字
+radius=10
+pi=3.14
+area=pi*radius**2
+formated_string='The area of circle with a radius %d is %.2f.'%(radius,area)# 2表示小数点后的2个有效数字
+python_libraries=['Django','Flask','NumPy','Matplotlib','Pandas']
+formated_string='The following are python libraries:%s'%(python_libraries)
+print(formated_string)# "The following are python libraries:['Django', 'Flask', 'NumPy', 'Matplotlib','Pandas']"
+
challenge='thirty days of python'
+print(challenge.count('y'))# 3
+print(challenge.count('y',7,14))# 1
+print(challenge.count('th'))# 2
+
+
+
endswith(): 检查字符串是否以指定的后缀结束
+
+
challenge='thirty days of python'
+print(challenge.endswith('on'))# True
+print(challenge.endswith('tion'))# False
+
+
+
expandtabs(): 用空格替换制表符字符,默认制表符大小为8。它接受制表符大小参数。
+
+
challenge='thirty\tdays\tof\tpython'
+print(challenge.expandtabs())# 'thirty days of python'
+print(challenge.expandtabs(10))# 'thirty days of python'
+
+
+
find(): 返回子字符串的第一次出现的索引,如果未找到则返回-1
+
+
challenge='thirty days of python'
+print(challenge.find('y'))# 5
+print(challenge.find('th'))# 0
+
+
+
rfind(): 返回子字符串的最后一次出现的索引,如果未找到则返回-1
+
+
challenge='thirty days of python'
+print(challenge.rfind('y'))# 16
+print(challenge.rfind('th'))# 17
+
first_name='Asabeneh'
+last_name='Yetayeh'
+age=250
+job='teacher'
+country='Finland'
+sentence='I am {}{}. I am a {}. I am {} years old. I live in {}.'.format(first_name,last_name,age,job,country)
+print(sentence)# I am Asabeneh Yetayeh. I am 250 years old. I am a teacher. I live in Finland.
+
+radius=10
+pi=3.14
+area=pi*radius**2
+result='The area of a circle with radius {} is {}'.format(str(radius),str(area))
+print(result)# The area of a circle with radius 10 is 314
+
challenge='thirty days of pythoonnn'
+print(challenge.strip('noth'))# 'irty days of py'
+
+
+
replace(): 用给定的字符串替换子字符串
+
+
challenge='thirty days of python'
+print(challenge.replace('python','coding'))# 'thirty days of coding'
+
+
+
split(): 使用给定的字符串或空格作为分隔符拆分字符串
+
+
challenge='thirty days of python'
+print(challenge.split())# ['thirty', 'days', 'of', 'python']
+challenge='thirty, days, of, python'
+print(challenge.split(', '))# ['thirty', 'days', 'of', 'python']
+
+
+
title(): 返回以标题格式的字符串
+
+
challenge='thirty days of python'
+print(challenge.title())# Thirty Days Of Python
+
+
+
swapcase(): 将所有大写字符转换为小写字符,将所有小写字符转换为大写字符
+
+
challenge='thirty days of python'
+print(challenge.swapcase())# THIRTY DAYS OF PYTHON
+challenge='Thirty Days Of Python'
+print(challenge.swapcase())# tHIRTY dAYS oF pYTHON
+
+
+
startswith(): 检查字符串是否以指定的字符串开头
+
+
challenge='thirty days of python'
+print(challenge.startswith('thirty'))# True
+
+challenge='30 days of python'
+print(challenge.startswith('thirty'))# False
+
+
+
+[<< Day 11](../11_Day_Functions/11_functions.md) | [Day 13>>](../13_Day_List_comprehension/13_list_comprehension.md)
+
+![30DaysOfPython](../images/30DaysOfPython_banner3@2x.png)
+
+- [📘 Day 12](#-day-12)
+ - [Modules](#modules)
+ - [What is a Module](#what-is-a-module)
+ - [Creating a Module](#creating-a-module)
+ - [Importing a Module](#importing-a-module)
+ - [Import Functions from a Module](#import-functions-from-a-module)
+ - [Import Functions from a Module and Renaming](#import-functions-from-a-module-and-renaming)
+ - [Import Built-in Modules](#import-built-in-modules)
+ - [OS Module](#os-module)
+ - [Sys Module](#sys-module)
+ - [Statistics Module](#statistics-module)
+ - [Math Module](#math-module)
+ - [String Module](#string-module)
+ - [Random Module](#random-module)
+ - [💻 Exercises: Day 12](#-exercises-day-12)
+ - [Exercises: Level 1](#exercises-level-1)
+ - [Exercises: Level 2](#exercises-level-2)
+ - [Exercises: Level 3](#exercises-level-3)
+
+# 📘 Day 12
+
+## Modules
+
+### What is a Module
+
+A module is a file containing a set of codes or a set of functions which can be included to an application. A module could be a file containing a single variable, a function or a big code base.
+
+### Creating a Module
+
+To create a module we write our codes in a python script and we save it as a .py file. Create a file named mymodule.py inside your project folder. Let us write some code in this file.
+
+```py
+# mymodule.py file
+def generate_full_name(firstname, lastname):
+ return firstname + ' ' + lastname
+```
+
+Create main.py file in your project directory and import the mymodule.py file.
+
+### Importing a Module
+
+To import the file we use the _import_ keyword and the name of the file only.
+
+```py
+# main.py file
+import mymodule
+print(mymodule.generate_full_name('Asabeneh', 'Yetayeh')) # Asabeneh Yetayeh
+```
+
+### Import Functions from a Module
+
+We can have many functions in a file and we can import all the functions differently.
+
+```py
+# main.py file
+from mymodule import generate_full_name, sum_two_nums, person, gravity
+print(generate_full_name('Asabneh','Yetayeh'))
+print(sum_two_nums(1,9))
+mass = 100;
+weight = mass * gravity
+print(weight)
+print(person['firstname'])
+```
+
+### Import Functions from a Module and Renaming
+
+During importing we can rename the name of the module.
+
+```py
+# main.py file
+from mymodule import generate_full_name as fullname, sum_two_nums as total, person as p, gravity as g
+print(fullname('Asabneh','Yetayeh'))
+print(total(1, 9))
+mass = 100;
+weight = mass * g
+print(weight)
+print(p)
+print(p['firstname'])
+```
+
+## Import Built-in Modules
+
+Like other programming languages we can also import modules by importing the file/function using the key word _import_. Let's import the common module we will use most of the time. Some of the common built-in modules: _math_, _datetime_, _os_,_sys_, _random_, _statistics_, _collections_, _json_,_re_
+
+### OS Module
+
+Using python _os_ module it is possible to automatically perform many operating system tasks. The OS module in Python provides functions for creating, changing current working directory, and removing a directory (folder), fetching its contents, changing and identifying the current directory.
+
+```py
+# import the module
+import os
+# Creating a directory
+os.mkdir('directory_name')
+# Changing the current directory
+os.chdir('path')
+# Getting current working directory
+os.getcwd()
+# Removing directory
+os.rmdir()
+```
+
+### Sys Module
+
+The sys module provides functions and variables used to manipulate different parts of the Python runtime environment. Function sys.argv returns a list of command line arguments passed to a Python script. The item at index 0 in this list is always the name of the script, at index 1 is the argument passed from the command line.
+
+Example of a script.py file:
+
+```py
+import sys
+#print(sys.argv[0], argv[1],sys.argv[2]) # this line would print out: filename argument1 argument2
+print('Welcome {}. Enjoy {} challenge!'.format(sys.argv[1], sys.argv[2]))
+```
+
+Now to check how this script works I wrote in command line:
+
+```sh
+python script.py Asabeneh 30DaysOfPython
+```
+
+The result:
+
+```sh
+Welcome Asabeneh. Enjoy 30DayOfPython challenge!
+```
+
+Some useful sys commands:
+
+```py
+# to exit sys
+sys.exit()
+# To know the largest integer variable it takes
+sys.maxsize
+# To know environment path
+sys.path
+# To know the version of python you are using
+sys.version
+```
+
+### Statistics Module
+
+The statistics module provides functions for mathematical statistics of numeric data. The popular statistical functions which are defined in this module: _mean_, _median_, _mode_, _stdev_ etc.
+
+```py
+from statistics import * # importing all the statistics modules
+ages = [20, 20, 4, 24, 25, 22, 26, 20, 23, 22, 26]
+print(mean(ages)) # ~22.9
+print(median(ages)) # 23
+print(mode(ages)) # 20
+print(stdev(ages)) # ~2.3
+```
+
+### Math Module
+
+Module containing many mathematical operations and constants.
+
+```py
+import math
+print(math.pi) # 3.141592653589793, pi constant
+print(math.sqrt(2)) # 1.4142135623730951, square root
+print(math.pow(2, 3)) # 8.0, exponential function
+print(math.floor(9.81)) # 9, rounding to the lowest
+print(math.ceil(9.81)) # 10, rounding to the highest
+print(math.log10(100)) # 2, logarithm with 10 as base
+```
+
+Now, we have imported the *math* module which contains lots of function which can help us to perform mathematical calculations. To check what functions the module has got, we can use _help(math)_, or _dir(math)_. This will display the available functions in the module. If we want to import only a specific function from the module we import it as follows:
+
+```py
+from math import pi
+print(pi)
+```
+
+It is also possible to import multiple functions at once
+
+```py
+
+from math import pi, sqrt, pow, floor, ceil, log10
+print(pi) # 3.141592653589793
+print(sqrt(2)) # 1.4142135623730951
+print(pow(2, 3)) # 8.0
+print(floor(9.81)) # 9
+print(ceil(9.81)) # 10
+print(math.log10(100)) # 2
+
+```
+
+But if we want to import all the function in math module we can use \* .
+
+```py
+from math import *
+print(pi) # 3.141592653589793, pi constant
+print(sqrt(2)) # 1.4142135623730951, square root
+print(pow(2, 3)) # 8.0, exponential
+print(floor(9.81)) # 9, rounding to the lowest
+print(ceil(9.81)) # 10, rounding to the highest
+print(math.log10(100)) # 2
+```
+
+When we import we can also rename the name of the function.
+
+```py
+from math import pi as PI
+print(PI) # 3.141592653589793
+```
+
+### String Module
+
+A string module is a useful module for many purposes. The example below shows some use of the string module.
+
+```py
+import string
+print(string.ascii_letters) # abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
+print(string.digits) # 0123456789
+print(string.punctuation) # !"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
+```
+
+### Random Module
+
+By now you are familiar with importing modules. Let us do one more import to get very familiar with it. Let us import _random_ module which gives us a random number between 0 and 0.9999.... The _random_ module has lots of functions but in this section we will only use _random_ and _randint_.
+
+```py
+from random import random, randint
+print(random()) # it doesn't take any arguments; it returns a value between 0 and 0.9999
+print(randint(5, 20)) # it returns a random integer number between [5, 20] inclusive
+```
+
+🌕 You are going far. Keep going! You have just completed day 12 challenges and you are 12 steps a head in to your way to greatness. Now do some exercises for your brain and muscles.
+
+## 💻 Exercises: Day 12
+
+### Exercises: Level 1
+
+1. Writ a function which generates a six digit/character random_user_id.
+ ```py
+ print(random_user_id());
+ '1ee33d'
+ ```
+2. Modify the previous task. Declare a function named user_id_gen_by_user. It doesn’t take any parameters but it takes two inputs using input(). One of the inputs is the number of characters and the second input is the number of IDs which are supposed to be generated.
+
+```py
+print(user_id_gen_by_user()) # user input: 5 5
+#output:
+#kcsy2
+#SMFYb
+#bWmeq
+#ZXOYh
+#2Rgxf
+
+print(user_id_gen_by_user()) # 16 5
+#1GCSgPLMaBAVQZ26
+#YD7eFwNQKNs7qXaT
+#ycArC5yrRupyG00S
+#UbGxOFI7UXSWAyKN
+#dIV0SSUTgAdKwStr
+```
+
+3. Write a function named rgb_color_gen. It will generate rgb colors (3 values ranging from 0 to 255 each).
+
+```py
+print(rgb_color_gen())
+# rgb(125,244,255) - the output should be in this form
+```
+
+### Exercises: Level 2
+
+1. Write a function list_of_hexa_colors which returns any number of hexadecimal colors in an array (six hexadecimal numbers written after #. Hexadecimal numeral system is made out of 16 symbols, 0-9 and first 6 letters of the alphabet, a-f. Check the task 6 for output examples).
+1. Write a function list_of_rgb_colors which returns any number of RGB colors in an array.
+1. Write a function generate_colors which can generate any number of hexa or rgb colors.
+
+```py
+ generate_colors('hexa', 3) # ['#a3e12f','#03ed55','#eb3d2b']
+ generate_colors('hexa', 1) # ['#b334ef']
+ generate_colors('rgb', 3) # ['rgb(5, 55, 175','rgb(50, 105, 100','rgb(15, 26, 80']
+ generate_colors('rgb', 1) # ['rgb(33,79, 176)']
+ ```
+
+### Exercises: Level 3
+
+1. Call your function shuffle_list, it takes a list as a parameter and it returns a shuffled list
+1. Write a function which returns an array of seven random numbers in a range of 0-9. All the numbers must be unique.
+
+🎉 CONGRATULATIONS ! 🎉
+
+[<< Day 11](../11_Day_Functions/11_functions.md) | [Day 13>>](../13_Day_List_comprehension/13_list_comprehension.md)
diff --git a/12_modules/index.html b/12_modules/index.html
new file mode 100644
index 0000000..998355f
--- /dev/null
+++ b/12_modules/index.html
@@ -0,0 +1,1706 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 12 modules - 30天入门Python全栈开发
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
A module is a file containing a set of codes or a set of functions which can be included to an application. A module could be a file containing a single variable, a function or a big code base.
To create a module we write our codes in a python script and we save it as a .py file. Create a file named mymodule.py inside your project folder. Let us write some code in this file.
Like other programming languages we can also import modules by importing the file/function using the key word import. Let's import the common module we will use most of the time. Some of the common built-in modules: math, datetime, os,sys, random, statistics, collections, json,re
Using python os module it is possible to automatically perform many operating system tasks. The OS module in Python provides functions for creating, changing current working directory, and removing a directory (folder), fetching its contents, changing and identifying the current directory.
+
# import the module
+importos
+# Creating a directory
+os.mkdir('directory_name')
+# Changing the current directory
+os.chdir('path')
+# Getting current working directory
+os.getcwd()
+# Removing directory
+os.rmdir()
+
The sys module provides functions and variables used to manipulate different parts of the Python runtime environment. Function sys.argv returns a list of command line arguments passed to a Python script. The item at index 0 in this list is always the name of the script, at index 1 is the argument passed from the command line.
+
Example of a script.py file:
+
importsys
+#print(sys.argv[0], argv[1],sys.argv[2]) # this line would print out: filename argument1 argument2
+print('Welcome {}. Enjoy {} challenge!'.format(sys.argv[1],sys.argv[2]))
+
+
Now to check how this script works I wrote in command line:
+
pythonscript.pyAsabeneh30DaysOfPython
+
+
The result:
+
WelcomeAsabeneh.Enjoy30DayOfPythonchallenge!
+
+
Some useful sys commands:
+
# to exit sys
+sys.exit()
+# To know the largest integer variable it takes
+sys.maxsize
+# To know environment path
+sys.path
+# To know the version of python you are using
+sys.version
+
The statistics module provides functions for mathematical statistics of numeric data. The popular statistical functions which are defined in this module: mean, median, mode, stdev etc.
+
fromstatisticsimport*# importing all the statistics modules
+ages=[20,20,4,24,25,22,26,20,23,22,26]
+print(mean(ages))# ~22.9
+print(median(ages))# 23
+print(mode(ages))# 20
+print(stdev(ages))# ~2.3
+
Module containing many mathematical operations and constants.
+
importmath
+print(math.pi)# 3.141592653589793, pi constant
+print(math.sqrt(2))# 1.4142135623730951, square root
+print(math.pow(2,3))# 8.0, exponential function
+print(math.floor(9.81))# 9, rounding to the lowest
+print(math.ceil(9.81))# 10, rounding to the highest
+print(math.log10(100))# 2, logarithm with 10 as base
+
+
Now, we have imported the math module which contains lots of function which can help us to perform mathematical calculations. To check what functions the module has got, we can use help(math), or dir(math). This will display the available functions in the module. If we want to import only a specific function from the module we import it as follows:
+
frommathimportpi
+print(pi)
+
+
It is also possible to import multiple functions at once
By now you are familiar with importing modules. Let us do one more import to get very familiar with it. Let us import random module which gives us a random number between 0 and 0.9999.... The random module has lots of functions but in this section we will only use random and randint.
+
fromrandomimportrandom,randint
+print(random())# it doesn't take any arguments; it returns a value between 0 and 0.9999
+print(randint(5,20))# it returns a random integer number between [5, 20] inclusive
+
+
🌕 You are going far. Keep going! You have just completed day 12 challenges and you are 12 steps a head in to your way to greatness. Now do some exercises for your brain and muscles.
Writ a function which generates a six digit/character random_user_id.
+
print(random_user_id());
+ '1ee33d'
+
+
Modify the previous task. Declare a function named user_id_gen_by_user. It doesn’t take any parameters but it takes two inputs using input(). One of the inputs is the number of characters and the second input is the number of IDs which are supposed to be generated.
Write a function list_of_hexa_colors which returns any number of hexadecimal colors in an array (six hexadecimal numbers written after #. Hexadecimal numeral system is made out of 16 symbols, 0-9 and first 6 letters of the alphabet, a-f. Check the task 6 for output examples).
+
Write a function list_of_rgb_colors which returns any number of RGB colors in an array.
+
Write a function generate_colors which can generate any number of hexa or rgb colors.
+
+
+[<< Day 12](../12_Day_Modules/12_modules.md) | [Day 14>>](../14_Day_Higher_order_functions/14_higher_order_functions.md)
+
+![30DaysOfPython](../images/30DaysOfPython_banner3@2x.png)
+
+- [📘 Day 13](#-day-13)
+ - [List Comprehension](#list-comprehension)
+ - [Lambda Function](#lambda-function)
+ - [Creating a Lambda Function](#creating-a-lambda-function)
+ - [Lambda Function Inside Another Function](#lambda-function-inside-another-function)
+ - [💻 Exercises: Day 13](#-exercises-day-13)
+
+# 📘 Day 13
+
+## List Comprehension
+
+List comprehension in Python is a compact way of creating a list from a sequence. It is a short way to create a new list. List comprehension is considerably faster than processing a list using the _for_ loop.
+
+```py
+# syntax
+[i for i in iterable if expression]
+```
+
+**Example:1**
+
+For instance if you want to change a string to a list of characters. You can use a couple of methods. Let's see some of them:
+
+```py
+# One way
+language = 'Python'
+lst = list(language) # changing the string to list
+print(type(lst)) # list
+print(lst) # ['P', 'y', 't', 'h', 'o', 'n']
+
+# Second way: list comprehension
+lst = [i for i in language]
+print(type(lst)) # list
+print(lst) # ['P', 'y', 't', 'h', 'o', 'n']
+
+```
+
+**Example:2**
+
+For instance if you want to generate a list of numbers
+
+```py
+# Generating numbers
+numbers = [i for i in range(11)] # to generate numbers from 0 to 10
+print(numbers) # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
+
+# It is possible to do mathematical operations during iteration
+squares = [i * i for i in range(11)]
+print(squares) # [0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
+
+# It is also possible to make a list of tuples
+numbers = [(i, i * i) for i in range(11)]
+print(numbers) # [(0, 0), (1, 1), (2, 4), (3, 9), (4, 16), (5, 25)]
+
+```
+
+**Example:2**
+
+List comprehension can be combined with if expression
+
+
+```py
+# Generating even numbers
+even_numbers = [i for i in range(21) if i % 2 == 0] # to generate even numbers list in range 0 to 21
+print(even_numbers) # [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
+
+# Generating odd numbers
+odd_numbers = [i for i in range(21) if i % 2 != 0] # to generate odd numbers in range 0 to 21
+print(odd_numbers) # [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
+# Filter numbers: let's filter out positive even numbers from the list below
+numbers = [-8, -7, -3, -1, 0, 1, 3, 4, 5, 7, 6, 8, 10]
+positive_even_numbers = [i for i in range(21) if i % 2 == 0 and i > 0]
+print(positive_even_numbers) # [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
+
+# Flattening a three dimensional array
+list_of_lists = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
+flattened_list = [ number for row in list_of_lists for number in row]
+print(flattened_list) # [1, 2, 3, 4, 5, 6, 7, 8, 9]
+```
+
+## Lambda Function
+
+Lambda function is a small anonymous function without a name. It can take any number of arguments, but can only have one expression. Lambda function is similar to anonymous functions in JavaScript. We need it when we want to write an anonymous function inside another function.
+
+### Creating a Lambda Function
+
+To create a lambda function we use _lambda_ keyword followed by a parameter(s), followed by an expression. See the syntax and the example below. Lambda function does not use return but it explicitly returns the expression.
+
+```py
+# syntax
+x = lambda param1, param2, param3: param1 + param2 + param2
+print(x(arg1, arg2, arg3))
+```
+
+**Example:**
+
+```py
+# Named function
+def add_two_nums(a, b):
+ return a + b
+
+print(add_two_nums(2, 3)) # 5
+# Lets change the above function to a lambda function
+add_two_nums = lambda a, b: a + b
+print(add_two_nums(2,3)) # 5
+
+# Self invoking lambda function
+(lambda a, b: a + b)(2,3) # 5 - need to encapsulate it in print() to see the result in the console
+
+square = lambda x : x ** 2
+print(square(3)) # 9
+cube = lambda x : x ** 3
+print(cube(3)) # 27
+
+# Multiple variables
+multiple_variable = lambda a, b, c: a ** 2 - 3 * b + 4 * c
+print(multiple_variable(5, 5, 3)) # 22
+```
+
+### Lambda Function Inside Another Function
+
+Using a lambda function inside another function.
+
+```py
+def power(x):
+ return lambda n : x ** n
+
+cube = power(2)(3) # function power now need 2 arguments to run, in separate rounded brackets
+print(cube) # 8
+two_power_of_five = power(2)(5)
+print(two_power_of_five) # 32
+```
+
+🌕 Keep up the good work. Keep the momentum going, the sky is the limit! You have just completed day 13 challenges and you are 13 steps a head in to your way to greatness. Now do some exercises for your brain and muscles.
+
+## 💻 Exercises: Day 13
+
+1. Filter only negative and zero in the list using list comprehension
+ ```py
+ numbers = [-4, -3, -2, -1, 0, 2, 4, 6]
+ ```
+2. Flatten the following list of lists of lists to a one dimensional list :
+
+ ```py
+ list_of_lists =[[[1, 2, 3]], [[4, 5, 6]], [[7, 8, 9]]]
+
+ output
+ [1, 2, 3, 4, 5, 6, 7, 8, 9]
+ ```
+
+3. Using list comprehension create the following list of tuples:
+ ```py
+ [(0, 1, 0, 0, 0, 0, 0),
+ (1, 1, 1, 1, 1, 1, 1),
+ (2, 1, 2, 4, 8, 16, 32),
+ (3, 1, 3, 9, 27, 81, 243),
+ (4, 1, 4, 16, 64, 256, 1024),
+ (5, 1, 5, 25, 125, 625, 3125),
+ (6, 1, 6, 36, 216, 1296, 7776),
+ (7, 1, 7, 49, 343, 2401, 16807),
+ (8, 1, 8, 64, 512, 4096, 32768),
+ (9, 1, 9, 81, 729, 6561, 59049),
+ (10, 1, 10, 100, 1000, 10000, 100000)]
+ ```
+4. Flatten the following list to a new list:
+ ```py
+ countries = [[('Finland', 'Helsinki')], [('Sweden', 'Stockholm')], [('Norway', 'Oslo')]]
+ output:
+ [['FINLAND','FIN', 'HELSINKI'], ['SWEDEN', 'SWE', 'STOCKHOLM'], ['NORWAY', 'NOR', 'OSLO']]
+ ```
+5. Change the following list to a list of dictionaries:
+ ```py
+ countries = [[('Finland', 'Helsinki')], [('Sweden', 'Stockholm')], [('Norway', 'Oslo')]]
+ output:
+ [{'country': 'FINLAND', 'city': 'HELSINKI'},
+ {'country': 'SWEDEN', 'city': 'STOCKHOLM'},
+ {'country': 'NORWAY', 'city': 'OSLO'}]
+ ```
+6. Change the following list of lists to a list of concatenated strings:
+ ```py
+ names = [[('Asabeneh', 'Yetayeh')], [('David', 'Smith')], [('Donald', 'Trump')], [('Bill', 'Gates')]]
+ output
+ ['Asabeneh Yetaeyeh', 'David Smith', 'Donald Trump', 'Bill Gates']
+ ```
+7. Write a lambda function which can solve a slope or y-intercept of linear functions.
+
+🎉 CONGRATULATIONS ! 🎉
+
+[<< Day 12](../12_Day_Modules/12_modules.md) | [Day 14>>](../14_Day_Higher_order_functions/14_higher_order_functions.md)
diff --git a/13_list_comprehension/index.html b/13_list_comprehension/index.html
new file mode 100644
index 0000000..223e7f3
--- /dev/null
+++ b/13_list_comprehension/index.html
@@ -0,0 +1,1405 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 13 list comprehension - 30天入门Python全栈开发
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
List comprehension in Python is a compact way of creating a list from a sequence. It is a short way to create a new list. List comprehension is considerably faster than processing a list using the for loop.
+
# syntax
+[iforiiniterableifexpression]
+
+
Example:1
+
For instance if you want to change a string to a list of characters. You can use a couple of methods. Let's see some of them:
+
# One way
+language='Python'
+lst=list(language)# changing the string to list
+print(type(lst))# list
+print(lst)# ['P', 'y', 't', 'h', 'o', 'n']
+
+# Second way: list comprehension
+lst=[iforiinlanguage]
+print(type(lst))# list
+print(lst)# ['P', 'y', 't', 'h', 'o', 'n']
+
+
Example:2
+
For instance if you want to generate a list of numbers
+
# Generating numbers
+numbers=[iforiinrange(11)]# to generate numbers from 0 to 10
+print(numbers)# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
+
+# It is possible to do mathematical operations during iteration
+squares=[i*iforiinrange(11)]
+print(squares)# [0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
+
+# It is also possible to make a list of tuples
+numbers=[(i,i*i)foriinrange(11)]
+print(numbers)# [(0, 0), (1, 1), (2, 4), (3, 9), (4, 16), (5, 25)]
+
+
Example:2
+
List comprehension can be combined with if expression
+
# Generating even numbers
+even_numbers=[iforiinrange(21)ifi%2==0]# to generate even numbers list in range 0 to 21
+print(even_numbers)# [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
+
+# Generating odd numbers
+odd_numbers=[iforiinrange(21)ifi%2!=0]# to generate odd numbers in range 0 to 21
+print(odd_numbers)# [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
+# Filter numbers: let's filter out positive even numbers from the list below
+numbers=[-8,-7,-3,-1,0,1,3,4,5,7,6,8,10]
+positive_even_numbers=[iforiinrange(21)ifi%2==0andi>0]
+print(positive_even_numbers)# [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
+
+# Flattening a three dimensional array
+list_of_lists=[[1,2,3],[4,5,6],[7,8,9]]
+flattened_list=[numberforrowinlist_of_listsfornumberinrow]
+print(flattened_list)# [1, 2, 3, 4, 5, 6, 7, 8, 9]
+
Lambda function is a small anonymous function without a name. It can take any number of arguments, but can only have one expression. Lambda function is similar to anonymous functions in JavaScript. We need it when we want to write an anonymous function inside another function.
To create a lambda function we use lambda keyword followed by a parameter(s), followed by an expression. See the syntax and the example below. Lambda function does not use return but it explicitly returns the expression.
# Named function
+defadd_two_nums(a,b):
+ returna+b
+
+print(add_two_nums(2,3))# 5
+# Lets change the above function to a lambda function
+add_two_nums=lambdaa,b:a+b
+print(add_two_nums(2,3))# 5
+
+# Self invoking lambda function
+(lambdaa,b:a+b)(2,3)# 5 - need to encapsulate it in print() to see the result in the console
+
+square=lambdax:x**2
+print(square(3))# 9
+cube=lambdax:x**3
+print(cube(3))# 27
+
+# Multiple variables
+multiple_variable=lambdaa,b,c:a**2-3*b+4*c
+print(multiple_variable(5,5,3))# 22
+
defpower(x):
+ returnlambdan:x**n
+
+cube=power(2)(3)# function power now need 2 arguments to run, in separate rounded brackets
+print(cube)# 8
+two_power_of_five=power(2)(5)
+print(two_power_of_five)# 32
+
+
🌕 Keep up the good work. Keep the momentum going, the sky is the limit! You have just completed day 13 challenges and you are 13 steps a head in to your way to greatness. Now do some exercises for your brain and muscles.
+
+
+[<< Day 13](../13_Day_List_comprehension/13_list_comprehension.md) | [Day 15>>](../15_Day_Python_type_errors/15_python_type_errors.md)
+
+![30DaysOfPython](../images/30DaysOfPython_banner3@2x.png)
+- [📘 Day 14](#-day-14)
+ - [Higher Order Functions](#higher-order-functions)
+ - [Function as a Parameter](#function-as-a-parameter)
+ - [Function as a Return Value](#function-as-a-return-value)
+ - [Python Closures](#python-closures)
+ - [Python Decorators](#python-decorators)
+ - [Creating Decorators](#creating-decorators)
+ - [Applying Multiple Decorators to a Single Function](#applying-multiple-decorators-to-a-single-function)
+ - [Accepting Parameters in Decorator Functions](#accepting-parameters-in-decorator-functions)
+ - [Built-in Higher Order Functions](#built-in-higher-order-functions)
+ - [Python - Map Function](#python---map-function)
+ - [Python - Filter Function](#python---filter-function)
+ - [Python - Reduce Function](#python---reduce-function)
+ - [💻 Exercises: Day 14](#-exercises-day-14)
+ - [Exercises: Level 1](#exercises-level-1)
+ - [Exercises: Level 2](#exercises-level-2)
+ - [Exercises: Level 3](#exercises-level-3)
+
+# 📘 Day 14
+
+## Higher Order Functions
+
+In Python functions are treated as first class citizens, allowing you to perform the following operations on functions:
+
+- A function can take one or more functions as parameters
+- A function can be returned as a result of another function
+- A function can be modified
+- A function can be assigned to a variable
+
+In this section, we will cover:
+
+1. Handling functions as parameters
+2. Returning functions as return value from another functions
+3. Using Python closures and decorators
+
+### Function as a Parameter
+
+```py
+def sum_numbers(nums): # normal function
+ return sum(nums) # a sad function abusing the built-in sum function :<
+
+def higher_order_function(f, lst): # function as a parameter
+ summation = f(lst)
+ return summation
+result = higher_order_function(sum_numbers, [1, 2, 3, 4, 5])
+print(result) # 15
+```
+
+### Function as a Return Value
+
+```py
+def square(x): # a square function
+ return x ** 2
+
+def cube(x): # a cube function
+ return x ** 3
+
+def absolute(x): # an absolute value function
+ if x >= 0:
+ return x
+ else:
+ return -(x)
+
+def higher_order_function(type): # a higher order function returning a function
+ if type == 'square':
+ return square
+ elif type == 'cube':
+ return cube
+ elif type == 'absolute':
+ return absolute
+
+result = higher_order_function('square')
+print(result(3)) # 9
+result = higher_order_function('cube')
+print(result(3)) # 27
+result = higher_order_function('absolute')
+print(result(-3)) # 3
+```
+
+You can see from the above example that the higher order function is returning different functions depending on the passed parameter
+
+## Python Closures
+
+Python allows a nested function to access the outer scope of the enclosing function. This is is known as a Closure. Let us have a look at how closures work in Python. In Python, closure is created by nesting a function inside another encapsulating function and then returning the inner function. See the example below.
+
+**Example:**
+
+```py
+def add_ten():
+ ten = 10
+ def add(num):
+ return num + ten
+ return add
+
+closure_result = add_ten()
+print(closure_result(5)) # 15
+print(closure_result(10)) # 20
+```
+
+## Python Decorators
+
+A decorator is a design pattern in Python that allows a user to add new functionality to an existing object without modifying its structure. Decorators are usually called before the definition of a function you want to decorate.
+
+### Creating Decorators
+
+To create a decorator function, we need an outer function with an inner wrapper function.
+
+**Example:**
+
+```py
+# Normal function
+def greeting():
+ return 'Welcome to Python'
+def uppercase_decorator(function):
+ def wrapper():
+ func = function()
+ make_uppercase = func.upper()
+ return make_uppercase
+ return wrapper
+g = uppercase_decorator(greeting)
+print(g()) # WELCOME TO PYTHON
+
+## Let us implement the example above with a decorator
+
+'''This decorator function is a higher order function
+that takes a function as a parameter'''
+def uppercase_decorator(function):
+ def wrapper():
+ func = function()
+ make_uppercase = func.upper()
+ return make_uppercase
+ return wrapper
+@uppercase_decorator
+def greeting():
+ return 'Welcome to Python'
+print(greeting()) # WELCOME TO PYTHON
+
+```
+
+### Applying Multiple Decorators to a Single Function
+
+```py
+
+'''These decorator functions are higher order functions
+that take functions as parameters'''
+
+# First Decorator
+def uppercase_decorator(function):
+ def wrapper():
+ func = function()
+ make_uppercase = func.upper()
+ return make_uppercase
+ return wrapper
+
+# Second decorator
+def split_string_decorator(function):
+ def wrapper():
+ func = function()
+ splitted_string = func.split()
+ return splitted_string
+
+ return wrapper
+
+@split_string_decorator
+@uppercase_decorator # order with decorators is important in this case - .upper() function does not work with lists
+def greeting():
+ return 'Welcome to Python'
+print(greeting()) # WELCOME TO PYTHON
+```
+
+### Accepting Parameters in Decorator Functions
+
+Most of the time we need our functions to take parameters, so we might need to define a decorator that accepts parameters.
+
+```py
+def decorator_with_parameters(function):
+ def wrapper_accepting_parameters(para1, para2, para3):
+ function(para1, para2, para3)
+ print("I live in {}".format(para3))
+ return wrapper_accepting_parameters
+
+@decorator_with_parameters
+def print_full_name(first_name, last_name, country):
+ print("I am {} {}. I love to teach.".format(
+ first_name, last_name, country))
+
+print_full_name("Asabeneh", "Yetayeh",'Finland')
+```
+
+## Built-in Higher Order Functions
+
+Some of the built-in higher order functions that we cover in this part are _map()_, _filter_, and _reduce_.
+Lambda function can be passed as a parameter and the best use case of lambda functions is in functions like map, filter and reduce.
+
+### Python - Map Function
+
+The map() function is a built-in function that takes a function and iterable as parameters.
+
+```py
+ # syntax
+ map(function, iterable)
+```
+
+**Example:1**
+
+```py
+numbers = [1, 2, 3, 4, 5] # iterable
+def square(x):
+ return x ** 2
+numbers_squared = map(square, numbers)
+print(list(numbers_squared)) # [1, 4, 9, 16, 25]
+# Lets apply it with a lambda function
+numbers_squared = map(lambda x : x ** 2, numbers)
+print(list(numbers_squared)) # [1, 4, 9, 16, 25]
+```
+
+**Example:2**
+
+```py
+numbers_str = ['1', '2', '3', '4', '5'] # iterable
+numbers_int = map(int, numbers_str)
+print(list(numbers_int)) # [1, 2, 3, 4, 5]
+```
+
+**Example:3**
+
+```py
+names = ['Asabeneh', 'Lidiya', 'Ermias', 'Abraham'] # iterable
+
+def change_to_upper(name):
+ return name.upper()
+
+names_upper_cased = map(change_to_upper, names)
+print(list(names_upper_cased)) # ['ASABENEH', 'LIDIYA', 'ERMIAS', 'ABRAHAM']
+
+# Let us apply it with a lambda function
+names_upper_cased = map(lambda name: name.upper(), names)
+print(list(names_upper_cased)) # ['ASABENEH', 'LIDIYA', 'ERMIAS', 'ABRAHAM']
+```
+
+What actually map does is iterating over a list. For instance, it changes the names to upper case and returns a new list.
+
+### Python - Filter Function
+
+The filter() function calls the specified function which returns boolean for each item of the specified iterable (list). It filters the items that satisfy the filtering criteria.
+
+```py
+ # syntax
+ filter(function, iterable)
+```
+
+**Example:1**
+
+```py
+# Lets filter only even nubers
+numbers = [1, 2, 3, 4, 5] # iterable
+
+def is_even(num):
+ if num % 2 == 0:
+ return True
+ return False
+
+even_numbers = filter(is_even, numbers)
+print(list(even_numbers)) # [2, 4]
+```
+
+**Example:2**
+
+```py
+numbers = [1, 2, 3, 4, 5] # iterable
+
+def is_odd(num):
+ if num % 2 != 0:
+ return True
+ return False
+
+odd_numbers = filter(is_odd, numbers)
+print(list(odd_numbers)) # [1, 3, 5]
+```
+
+```py
+# Filter long name
+names = ['Asabeneh', 'Lidiya', 'Ermias', 'Abraham'] # iterable
+def is_name_long(name):
+ if len(name) > 7:
+ return True
+ return False
+
+long_names = filter(is_name_long, names)
+print(list(long_names)) # ['Asabeneh']
+```
+
+### Python - Reduce Function
+
+The _reduce()_ function is defined in the functools module and we should import it from this module. Like map and filter it takes two parameters, a function and an iterable. However, it does not return another iterable, instead it returns a single value.
+**Example:1**
+
+```py
+numbers_str = ['1', '2', '3', '4', '5'] # iterable
+def add_two_nums(x, y):
+ return int(x) + int(y)
+
+total = reduce(add_two_nums, numbers_str)
+print(total) # 15
+```
+
+## 💻 Exercises: Day 14
+
+```py
+countries = ['Estonia', 'Finland', 'Sweden', 'Denmark', 'Norway', 'Iceland']
+names = ['Asabeneh', 'Lidiya', 'Ermias', 'Abraham']
+numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
+```
+
+### Exercises: Level 1
+
+1. Explain the difference between map, filter, and reduce.
+2. Explain the difference between higher order function, closure and decorator
+3. Define a call function before map, filter or reduce, see examples.
+4. Use for loop to print each country in the countries list.
+5. Use for to print each name in the names list.
+6. Use for to print each number in the numbers list.
+
+### Exercises: Level 2
+
+1. Use map to create a new list by changing each country to uppercase in the countries list
+1. Use map to create a new list by changing each number to its square in the numbers list
+1. Use map to change each name to uppercase in the names list
+1. Use filter to filter out countries containing 'land'.
+1. Use filter to filter out countries having exactly six characters.
+1. Use filter to filter out countries containing six letters and more in the country list.
+1. Use filter to filter out countries starting with an 'E'
+1. Chain two or more list iterators (eg. arr.map(callback).filter(callback).reduce(callback))
+1. Declare a function called get_string_lists which takes a list as a parameter and then returns a list containing only string items.
+1. Use reduce to sum all the numbers in the numbers list.
+1. Use reduce to concatenate all the countries and to produce this sentence: Estonia, Finland, Sweden, Denmark, Norway, and Iceland are north European countries
+1. Declare a function called categorize_countries that returns a list of countries with some common pattern (you can find the [countries list](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/countries.py) in this repository as countries.js(eg 'land', 'ia', 'island', 'stan')).
+1. Create a function returning a dictionary, where keys stand for starting letters of countries and values are the number of country names starting with that letter.
+2. Declare a get_first_ten_countries function - it returns a list of first ten countries from the countries.js list in the data folder.
+1. Declare a get_last_ten_countries function that returns the last ten countries in the countries list.
+
+### Exercises: Level 3
+
+1. Use the countries_data.py (https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/countries-data.py) file and follow the tasks below:
+ - Sort countries by name, by capital, by population
+ - Sort out the ten most spoken languages by location.
+ - Sort out the ten most populated countries.
+
+🎉 CONGRATULATIONS ! 🎉
+
+[<< Day 13](../13_Day_List_comprehension/13_list_comprehension.md) | [Day 15>>](../15_Day_Python_type_errors/15_python_type_errors.md)
\ No newline at end of file
diff --git a/14_higher_order_functions/index.html b/14_higher_order_functions/index.html
new file mode 100644
index 0000000..d67d355
--- /dev/null
+++ b/14_higher_order_functions/index.html
@@ -0,0 +1,1772 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 14 higher order functions - 30天入门Python全栈开发
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
defsum_numbers(nums):# normal function
+ returnsum(nums)# a sad function abusing the built-in sum function :<
+
+defhigher_order_function(f,lst):# function as a parameter
+ summation=f(lst)
+ returnsummation
+result=higher_order_function(sum_numbers,[1,2,3,4,5])
+print(result)# 15
+
defsquare(x):# a square function
+ returnx**2
+
+defcube(x):# a cube function
+ returnx**3
+
+defabsolute(x):# an absolute value function
+ ifx>=0:
+ returnx
+ else:
+ return-(x)
+
+defhigher_order_function(type):# a higher order function returning a function
+ iftype=='square':
+ returnsquare
+ eliftype=='cube':
+ returncube
+ eliftype=='absolute':
+ returnabsolute
+
+result=higher_order_function('square')
+print(result(3))# 9
+result=higher_order_function('cube')
+print(result(3))# 27
+result=higher_order_function('absolute')
+print(result(-3))# 3
+
+
You can see from the above example that the higher order function is returning different functions depending on the passed parameter
Python allows a nested function to access the outer scope of the enclosing function. This is is known as a Closure. Let us have a look at how closures work in Python. In Python, closure is created by nesting a function inside another encapsulating function and then returning the inner function. See the example below.
A decorator is a design pattern in Python that allows a user to add new functionality to an existing object without modifying its structure. Decorators are usually called before the definition of a function you want to decorate.
To create a decorator function, we need an outer function with an inner wrapper function.
+
Example:
+
# Normal function
+defgreeting():
+ return'Welcome to Python'
+defuppercase_decorator(function):
+ defwrapper():
+ func=function()
+ make_uppercase=func.upper()
+ returnmake_uppercase
+ returnwrapper
+g=uppercase_decorator(greeting)
+print(g())# WELCOME TO PYTHON
+
+## Let us implement the example above with a decorator
+
+'''This decorator function is a higher order function
+that takes a function as a parameter'''
+defuppercase_decorator(function):
+ defwrapper():
+ func=function()
+ make_uppercase=func.upper()
+ returnmake_uppercase
+ returnwrapper
+@uppercase_decorator
+defgreeting():
+ return'Welcome to Python'
+print(greeting())# WELCOME TO PYTHON
+
+
Applying Multiple Decorators to a Single Function⚓︎
+
'''These decorator functions are higher order functions
+that take functions as parameters'''
+
+# First Decorator
+defuppercase_decorator(function):
+ defwrapper():
+ func=function()
+ make_uppercase=func.upper()
+ returnmake_uppercase
+ returnwrapper
+
+# Second decorator
+defsplit_string_decorator(function):
+ defwrapper():
+ func=function()
+ splitted_string=func.split()
+ returnsplitted_string
+
+ returnwrapper
+
+@split_string_decorator
+@uppercase_decorator# order with decorators is important in this case - .upper() function does not work with lists
+defgreeting():
+ return'Welcome to Python'
+print(greeting())# WELCOME TO PYTHON
+
Most of the time we need our functions to take parameters, so we might need to define a decorator that accepts parameters.
+
defdecorator_with_parameters(function):
+ defwrapper_accepting_parameters(para1,para2,para3):
+ function(para1,para2,para3)
+ print("I live in {}".format(para3))
+ returnwrapper_accepting_parameters
+
+@decorator_with_parameters
+defprint_full_name(first_name,last_name,country):
+ print("I am {}{}. I love to teach.".format(
+ first_name,last_name,country))
+
+print_full_name("Asabeneh","Yetayeh",'Finland')
+
Some of the built-in higher order functions that we cover in this part are map(), filter, and reduce.
+Lambda function can be passed as a parameter and the best use case of lambda functions is in functions like map, filter and reduce.
names=['Asabeneh','Lidiya','Ermias','Abraham']# iterable
+
+defchange_to_upper(name):
+ returnname.upper()
+
+names_upper_cased=map(change_to_upper,names)
+print(list(names_upper_cased))# ['ASABENEH', 'LIDIYA', 'ERMIAS', 'ABRAHAM']
+
+# Let us apply it with a lambda function
+names_upper_cased=map(lambdaname:name.upper(),names)
+print(list(names_upper_cased))# ['ASABENEH', 'LIDIYA', 'ERMIAS', 'ABRAHAM']
+
+
What actually map does is iterating over a list. For instance, it changes the names to upper case and returns a new list.
The filter() function calls the specified function which returns boolean for each item of the specified iterable (list). It filters the items that satisfy the filtering criteria.
The reduce() function is defined in the functools module and we should import it from this module. Like map and filter it takes two parameters, a function and an iterable. However, it does not return another iterable, instead it returns a single value.
+Example:1
Use map to create a new list by changing each country to uppercase in the countries list
+
Use map to create a new list by changing each number to its square in the numbers list
+
Use map to change each name to uppercase in the names list
+
Use filter to filter out countries containing 'land'.
+
Use filter to filter out countries having exactly six characters.
+
Use filter to filter out countries containing six letters and more in the country list.
+
Use filter to filter out countries starting with an 'E'
+
Chain two or more list iterators (eg. arr.map(callback).filter(callback).reduce(callback))
+
Declare a function called get_string_lists which takes a list as a parameter and then returns a list containing only string items.
+
Use reduce to sum all the numbers in the numbers list.
+
Use reduce to concatenate all the countries and to produce this sentence: Estonia, Finland, Sweden, Denmark, Norway, and Iceland are north European countries
+
Declare a function called categorize_countries that returns a list of countries with some common pattern (you can find the countries list in this repository as countries.js(eg 'land', 'ia', 'island', 'stan')).
+
Create a function returning a dictionary, where keys stand for starting letters of countries and values are the number of country names starting with that letter.
+
Declare a get_first_ten_countries function - it returns a list of first ten countries from the countries.js list in the data folder.
+
Declare a get_last_ten_countries function that returns the last ten countries in the countries list.
+
+
+[<< Day 14](../14_Day_Higher_order_functions/14_higher_order_functions.md) | [Day 16 >>](../16_Day_Python_date_time/16_python_datetime.md)
+
+![30DaysOfPython](../images/30DaysOfPython_banner3@2x.png)
+- [📘 Day 15](#-day-15)
+ - [Python Error Types](#python-error-types)
+ - [SyntaxError](#syntaxerror)
+ - [NameError](#nameerror)
+ - [IndexError](#indexerror)
+ - [ModuleNotFoundError](#modulenotfounderror)
+ - [AttributeError](#attributeerror)
+ - [KeyError](#keyerror)
+ - [TypeError](#typeerror)
+ - [ImportError](#importerror)
+ - [ValueError](#valueerror)
+ - [ZeroDivisionError](#zerodivisionerror)
+ - [💻 Exercises: Day 15](#-exercises-day-15)
+
+# 📘 Day 15
+
+## Python Error Types
+
+When we write code it is common that we make a typo or some other common error. If our code fails to run, the Python interpreter will display a message, containing feedback with information on where the problem occurs and the type of an error. It will also sometimes gives us suggestions on a possible fix. Understanding different types of errors in programming languages will help us to debug our code quickly and also it makes us better at what we do.
+
+Let us see the most common error types one by one. First let us open our Python interactive shell. Go to your you computer terminal and write 'python'. The python interactive shell will be opened.
+
+### SyntaxError
+
+**Example 1: SyntaxError**
+
+```py
+asabeneh@Asabeneh:~$ python
+Python 3.9.6 (default, Jun 28 2021, 15:26:21)
+[Clang 11.0.0 (clang-1100.0.33.8)] on darwin
+Type "help", "copyright", "credits" or "license" for more information.
+>>> print 'hello world'
+ File "", line 1
+ print 'hello world'
+ ^
+SyntaxError: Missing parentheses in call to 'print'. Did you mean print('hello world')?
+>>>
+```
+
+As you can see we made a syntax error because we forgot to enclose the string with parenthesis and Python already suggests the solution. Let us fix it.
+
+```py
+asabeneh@Asabeneh:~$ python
+Python 3.9.6 (default, Jun 28 2021, 15:26:21)
+[Clang 11.0.0 (clang-1100.0.33.8)] on darwin
+Type "help", "copyright", "credits" or "license" for more information.
+>>> print 'hello world'
+ File "", line 1
+ print 'hello world'
+ ^
+SyntaxError: Missing parentheses in call to 'print'. Did you mean print('hello world')?
+>>> print('hello world')
+hello world
+>>>
+```
+
+The error was a _SyntaxError_. After the fix our code was executed without a hitch. Let see more error types.
+
+### NameError
+
+**Example 1: NameError**
+
+```py
+asabeneh@Asabeneh:~$ python
+Python 3.9.6 (default, Jun 28 2021, 15:26:21)
+[Clang 11.0.0 (clang-1100.0.33.8)] on darwin
+Type "help", "copyright", "credits" or "license" for more information.
+>>> print(age)
+Traceback (most recent call last):
+ File "", line 1, in
+NameError: name 'age' is not defined
+>>>
+```
+
+As you can see from the message above, name age is not defined. Yes, it is true that we did not define an age variable but we were trying to print it out as if we had had declared it. Now, lets fix this by declaring it and assigning with a value.
+
+```py
+asabeneh@Asabeneh:~$ python
+Python 3.9.6 (default, Jun 28 2021, 15:26:21)
+[Clang 11.0.0 (clang-1100.0.33.8)] on darwin
+Type "help", "copyright", "credits" or "license" for more information.
+>>> print(age)
+Traceback (most recent call last):
+ File "", line 1, in
+NameError: name 'age' is not defined
+>>> age = 25
+>>> print(age)
+25
+>>>
+```
+
+The type of error was a _NameError_. We debugged the error by defining the variable name.
+
+### IndexError
+
+**Example 1: IndexError**
+
+```py
+asabeneh@Asabeneh:~$ python
+Python 3.9.6 (default, Jun 28 2021, 15:26:21)
+[Clang 11.0.0 (clang-1100.0.33.8)] on darwin
+Type "help", "copyright", "credits" or "license" for more information.
+>>> numbers = [1, 2, 3, 4, 5]
+>>> numbers[5]
+Traceback (most recent call last):
+ File "", line 1, in
+IndexError: list index out of range
+>>>
+```
+
+In the example above, Python raised an _IndexError_, because the list has only indexes from 0 to 4 , so it was out of range.
+
+### ModuleNotFoundError
+
+**Example 1: ModuleNotFoundError**
+
+```py
+asabeneh@Asabeneh:~$ python
+Python 3.9.6 (default, Jun 28 2021, 15:26:21)
+[Clang 11.0.0 (clang-1100.0.33.8)] on darwin
+Type "help", "copyright", "credits" or "license" for more information.
+>>> import maths
+Traceback (most recent call last):
+ File "", line 1, in
+ModuleNotFoundError: No module named 'maths'
+>>>
+```
+
+In the example above, I added an extra s to math deliberately and _ModuleNotFoundError_ was raised. Lets fix it by removing the extra s from math.
+
+```py
+asabeneh@Asabeneh:~$ python
+Python 3.9.6 (default, Jun 28 2021, 15:26:21)
+[Clang 11.0.0 (clang-1100.0.33.8)] on darwin
+Type "help", "copyright", "credits" or "license" for more information.
+>>> import maths
+Traceback (most recent call last):
+ File "", line 1, in
+ModuleNotFoundError: No module named 'maths'
+>>> import math
+>>>
+```
+
+We fixed it, so let's use some of the functions from the math module.
+
+### AttributeError
+
+**Example 1: AttributeError**
+
+```py
+asabeneh@Asabeneh:~$ python
+Python 3.9.6 (default, Jun 28 2021, 15:26:21)
+[Clang 11.0.0 (clang-1100.0.33.8)] on darwin
+Type "help", "copyright", "credits" or "license" for more information.
+>>> import maths
+Traceback (most recent call last):
+ File "", line 1, in
+ModuleNotFoundError: No module named 'maths'
+>>> import math
+>>> math.PI
+Traceback (most recent call last):
+ File "", line 1, in
+AttributeError: module 'math' has no attribute 'PI'
+>>>
+```
+
+As you can see, I made a mistake again! Instead of pi, I tried to call a PI function from maths module. It raised an attribute error, it means, that the function does not exist in the module. Lets fix it by changing from PI to pi.
+
+```py
+asabeneh@Asabeneh:~$ python
+Python 3.9.6 (default, Jun 28 2021, 15:26:21)
+[Clang 11.0.0 (clang-1100.0.33.8)] on darwin
+Type "help", "copyright", "credits" or "license" for more information.
+>>> import maths
+Traceback (most recent call last):
+ File "", line 1, in
+ModuleNotFoundError: No module named 'maths'
+>>> import math
+>>> math.PI
+Traceback (most recent call last):
+ File "", line 1, in
+AttributeError: module 'math' has no attribute 'PI'
+>>> math.pi
+3.141592653589793
+>>>
+```
+
+Now, when we call pi from the math module we got the result.
+
+### KeyError
+
+**Example 1: KeyError**
+
+```py
+asabeneh@Asabeneh:~$ python
+Python 3.9.6 (default, Jun 28 2021, 15:26:21)
+[Clang 11.0.0 (clang-1100.0.33.8)] on darwin
+Type "help", "copyright", "credits" or "license" for more information.
+>>> users = {'name':'Asab', 'age':250, 'country':'Finland'}
+>>> users['name']
+'Asab'
+>>> users['county']
+Traceback (most recent call last):
+ File "", line 1, in
+KeyError: 'county'
+>>>
+```
+
+As you can see, there was a typo in the key used to get the dictionary value. so, this is a key error and the fix is quite straight forward. Let's do this!
+
+```py
+asabeneh@Asabeneh:~$ python
+Python 3.9.6 (default, Jun 28 2021, 15:26:21)
+[Clang 11.0.0 (clang-1100.0.33.8)] on darwin
+Type "help", "copyright", "credits" or "license" for more information.
+>>> user = {'name':'Asab', 'age':250, 'country':'Finland'}
+>>> user['name']
+'Asab'
+>>> user['county']
+Traceback (most recent call last):
+ File "", line 1, in
+KeyError: 'county'
+>>> user['country']
+'Finland'
+>>>
+```
+
+We debugged the error, our code ran and we got the value.
+
+### TypeError
+
+**Example 1: TypeError**
+
+```py
+asabeneh@Asabeneh:~$ python
+Python 3.9.6 (default, Jun 28 2021, 15:26:21)
+[Clang 11.0.0 (clang-1100.0.33.8)] on darwin
+Type "help", "copyright", "credits" or "license" for more information.
+>>> 4 + '3'
+Traceback (most recent call last):
+ File "", line 1, in
+TypeError: unsupported operand type(s) for +: 'int' and 'str'
+>>>
+```
+
+In the example above, a TypeError is raised because we cannot add a number to a string. First solution would be to convert the string to int or float. Another solution would be converting the number to a string (the result then would be '43'). Let us follow the first fix.
+
+```py
+asabeneh@Asabeneh:~$ python
+Python 3.9.6 (default, Jun 28 2021, 15:26:21)
+[Clang 11.0.0 (clang-1100.0.33.8)] on darwin
+Type "help", "copyright", "credits" or "license" for more information.
+>>> 4 + '3'
+Traceback (most recent call last):
+ File "", line 1, in
+TypeError: unsupported operand type(s) for +: 'int' and 'str'
+>>> 4 + int('3')
+7
+>>> 4 + float('3')
+7.0
+>>>
+```
+
+Error removed and we got the result we expected.
+
+### ImportError
+
+**Example 1: TypeError**
+
+```py
+asabeneh@Asabeneh:~$ python
+Python 3.9.6 (default, Jun 28 2021, 15:26:21)
+[Clang 11.0.0 (clang-1100.0.33.8)] on darwin
+Type "help", "copyright", "credits" or "license" for more information.
+>>> from math import power
+Traceback (most recent call last):
+ File "", line 1, in
+ImportError: cannot import name 'power' from 'math'
+>>>
+```
+
+There is no function called power in the math module, it goes with a different name: _pow_. Let's correct it:
+
+```py
+asabeneh@Asabeneh:~$ python
+Python 3.9.6 (default, Jun 28 2021, 15:26:21)
+[Clang 11.0.0 (clang-1100.0.33.8)] on darwin
+Type "help", "copyright", "credits" or "license" for more information.
+>>> from math import power
+Traceback (most recent call last):
+ File "", line 1, in
+ImportError: cannot import name 'power' from 'math'
+>>> from math import pow
+>>> pow(2,3)
+8.0
+>>>
+```
+
+### ValueError
+
+```py
+asabeneh@Asabeneh:~$ python
+Python 3.9.6 (default, Jun 28 2021, 15:26:21)
+[Clang 11.0.0 (clang-1100.0.33.8)] on darwin
+Type "help", "copyright", "credits" or "license" for more information.
+>>> int('12a')
+Traceback (most recent call last):
+ File "", line 1, in
+ValueError: invalid literal for int() with base 10: '12a'
+>>>
+```
+
+In this case we cannot change the given string to a number, because of the 'a' letter in it.
+
+### ZeroDivisionError
+
+```py
+asabeneh@Asabeneh:~$ python
+Python 3.9.6 (default, Jun 28 2021, 15:26:21)
+[Clang 11.0.0 (clang-1100.0.33.8)] on darwin
+Type "help", "copyright", "credits" or "license" for more information.
+>>> 1/0
+Traceback (most recent call last):
+ File "", line 1, in
+ZeroDivisionError: division by zero
+>>>
+```
+
+We cannot divide a number by zero.
+
+We have covered some of the python error types, if you want to check more about it check the python documentation about python error types.
+If you are good at reading the error types then you will be able to fix your bugs fast and you will also become a better programmer.
+
+🌕 You are excelling. You made it to half way to your way to greatness. Now do some exercises for your brain and for your muscle.
+
+## 💻 Exercises: Day 15
+
+1. Open you python interactive shell and try all the examples covered in this section.
+
+🎉 CONGRATULATIONS ! 🎉
+
+[<< Day 14](../14_Day_Higher_order_functions/14_higher_order_functions.md) | [Day 16 >>](../16_Day_Python_date_time/16_python_datetime.md)
\ No newline at end of file
diff --git a/15_python_type_errors/index.html b/15_python_type_errors/index.html
new file mode 100644
index 0000000..57102a0
--- /dev/null
+++ b/15_python_type_errors/index.html
@@ -0,0 +1,1646 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 15 python type errors - 30天入门Python全栈开发
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
When we write code it is common that we make a typo or some other common error. If our code fails to run, the Python interpreter will display a message, containing feedback with information on where the problem occurs and the type of an error. It will also sometimes gives us suggestions on a possible fix. Understanding different types of errors in programming languages will help us to debug our code quickly and also it makes us better at what we do.
+
Let us see the most common error types one by one. First let us open our Python interactive shell. Go to your you computer terminal and write 'python'. The python interactive shell will be opened.
As you can see we made a syntax error because we forgot to enclose the string with parenthesis and Python already suggests the solution. Let us fix it.
As you can see from the message above, name age is not defined. Yes, it is true that we did not define an age variable but we were trying to print it out as if we had had declared it. Now, lets fix this by declaring it and assigning with a value.
As you can see, I made a mistake again! Instead of pi, I tried to call a PI function from maths module. It raised an attribute error, it means, that the function does not exist in the module. Lets fix it by changing from PI to pi.
As you can see, there was a typo in the key used to get the dictionary value. so, this is a key error and the fix is quite straight forward. Let's do this!
In the example above, a TypeError is raised because we cannot add a number to a string. First solution would be to convert the string to int or float. Another solution would be converting the number to a string (the result then would be '43'). Let us follow the first fix.
We have covered some of the python error types, if you want to check more about it check the python documentation about python error types.
+If you are good at reading the error types then you will be able to fix your bugs fast and you will also become a better programmer.
+
🌕 You are excelling. You made it to half way to your way to greatness. Now do some exercises for your brain and for your muscle.
+
+[<< Day 15](../15_Day_Python_type_errors/15_python_type_errors.md) | [Day 17 >>](../17_Day_Exception_handling/17_exception_handling.md)
+
+![30DaysOfPython](../images/30DaysOfPython_banner3@2x.png)
+- [📘 Day 16](#-day-16)
+ - [Python *datetime*](#python-datetime)
+ - [Getting *datetime* Information](#getting-datetime-information)
+ - [Formatting Date Output Using *strftime*](#formatting-date-output-using-strftime)
+ - [String to Time Using *strptime*](#string-to-time-using-strptime)
+ - [Using *date* from *datetime*](#using-date-from-datetime)
+ - [Time Objects to Represent Time](#time-objects-to-represent-time)
+ - [Difference Between Two Points in Time Using](#difference-between-two-points-in-time-using)
+ - [Difference Between Two Points in Time Using *timedelata*](#difference-between-two-points-in-time-using-timedelata)
+ - [💻 Exercises: Day 16](#-exercises-day-16)
+# 📘 Day 16
+
+## Python *datetime*
+
+Python has got _datetime_ module to handle date and time.
+
+```py
+import datetime
+print(dir(datetime))
+['MAXYEAR', 'MINYEAR', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'date', 'datetime', 'datetime_CAPI', 'sys', 'time', 'timedelta', 'timezone', 'tzinfo']
+```
+
+With dir or help built-in commands it is possible to know the available functions in a certain module. As you can see, in the datetime module there are many functions, but we will focus on _date_, _datetime_, _time_ and _timedelta_. Let se see them one by one.
+
+### Getting *datetime* Information
+
+```py
+from datetime import datetime
+now = datetime.now()
+print(now) # 2021-07-08 07:34:46.549883
+day = now.day # 8
+month = now.month # 7
+year = now.year # 2021
+hour = now.hour # 7
+minute = now.minute # 38
+second = now.second
+timestamp = now.timestamp()
+print(day, month, year, hour, minute)
+print('timestamp', timestamp)
+print(f'{day}/{month}/{year}, {hour}:{minute}') # 8/7/2021, 7:38
+```
+
+Timestamp or Unix timestamp is the number of seconds elapsed from 1st of January 1970 UTC.
+
+### Formatting Date Output Using *strftime*
+
+```py
+from datetime import datetime
+new_year = datetime(2020, 1, 1)
+print(new_year) # 2020-01-01 00:00:00
+day = new_year.day
+month = new_year.month
+year = new_year.year
+hour = new_year.hour
+minute = new_year.minute
+second = new_year.second
+print(day, month, year, hour, minute) #1 1 2020 0 0
+print(f'{day}/{month}/{year}, {hour}:{minute}') # 1/1/2020, 0:0
+
+```
+
+Formatting date time using *strftime* method and the documentation can be found [here](https://strftime.org/).
+
+```py
+from datetime import datetime
+# current date and time
+now = datetime.now()
+t = now.strftime("%H:%M:%S")
+print("time:", t)
+time_one = now.strftime("%m/%d/%Y, %H:%M:%S")
+# mm/dd/YY H:M:S format
+print("time one:", time_one)
+time_two = now.strftime("%d/%m/%Y, %H:%M:%S")
+# dd/mm/YY H:M:S format
+print("time two:", time_two)
+```
+
+```sh
+time: 01:05:01
+time one: 12/05/2019, 01:05:01
+time two: 05/12/2019, 01:05:01
+```
+
+Here are all the _strftime_ symbols we use to format time. An example of all the formats for this module.
+
+![strftime](../images/strftime.png)
+
+### String to Time Using *strptime*
+Here is a [documentation](https://www.programiz.com/python-programming/datetime/strptimet) hat helps to understand the format.
+
+```py
+from datetime import datetime
+date_string = "5 December, 2019"
+print("date_string =", date_string)
+date_object = datetime.strptime(date_string, "%d %B, %Y")
+print("date_object =", date_object)
+```
+
+```sh
+date_string = 5 December, 2019
+date_object = 2019-12-05 00:00:00
+```
+
+### Using *date* from *datetime*
+
+```py
+from datetime import date
+d = date(2020, 1, 1)
+print(d)
+print('Current date:', d.today()) # 2019-12-05
+# date object of today's date
+today = date.today()
+print("Current year:", today.year) # 2019
+print("Current month:", today.month) # 12
+print("Current day:", today.day) # 5
+```
+
+### Time Objects to Represent Time
+
+```py
+from datetime import time
+# time(hour = 0, minute = 0, second = 0)
+a = time()
+print("a =", a)
+# time(hour, minute and second)
+b = time(10, 30, 50)
+print("b =", b)
+# time(hour, minute and second)
+c = time(hour=10, minute=30, second=50)
+print("c =", c)
+# time(hour, minute, second, microsecond)
+d = time(10, 30, 50, 200555)
+print("d =", d)
+```
+
+output
+a = 00:00:00
+b = 10:30:50
+c = 10:30:50
+d = 10:30:50.200555
+
+### Difference Between Two Points in Time Using
+
+```py
+today = date(year=2019, month=12, day=5)
+new_year = date(year=2020, month=1, day=1)
+time_left_for_newyear = new_year - today
+# Time left for new year: 27 days, 0:00:00
+print('Time left for new year: ', time_left_for_newyear)
+
+t1 = datetime(year = 2019, month = 12, day = 5, hour = 0, minute = 59, second = 0)
+t2 = datetime(year = 2020, month = 1, day = 1, hour = 0, minute = 0, second = 0)
+diff = t2 - t1
+print('Time left for new year:', diff) # Time left for new year: 26 days, 23: 01: 00
+```
+
+### Difference Between Two Points in Time Using *timedelata*
+
+```py
+from datetime import timedelta
+t1 = timedelta(weeks=12, days=10, hours=4, seconds=20)
+t2 = timedelta(days=7, hours=5, minutes=3, seconds=30)
+t3 = t1 - t2
+print("t3 =", t3)
+```
+
+```sh
+ date_string = 5 December, 2019
+ date_object = 2019-12-05 00:00:00
+ t3 = 86 days, 22:56:50
+```
+
+🌕 You are an extraordinary. You are 16 steps a head to your way to greatness. Now do some exercises for your brain and muscles.
+
+## 💻 Exercises: Day 16
+
+1. Get the current day, month, year, hour, minute and timestamp from datetime module
+1. Format the current date using this format: "%m/%d/%Y, %H:%M:%S")
+1. Today is 5 December, 2019. Change this time string to time.
+1. Calculate the time difference between now and new year.
+1. Calculate the time difference between 1 January 1970 and now.
+1. Think, what can you use the datetime module for? Examples:
+ - Time series analysis
+ - To get a timestamp of any activities in an application
+ - Adding posts on a blog
+
+🎉 CONGRATULATIONS ! 🎉
+
+[<< Day 15](../15_Day_Python_type_errors/15_python_type_errors.md) | [Day 17 >>](../17_Day_Exception_handling/17_exception_handling.md)
\ No newline at end of file
diff --git a/16_python_datetime/index.html b/16_python_datetime/index.html
new file mode 100644
index 0000000..9ca7a4c
--- /dev/null
+++ b/16_python_datetime/index.html
@@ -0,0 +1,1473 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 16 python datetime - 30天入门Python全栈开发
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
With dir or help built-in commands it is possible to know the available functions in a certain module. As you can see, in the datetime module there are many functions, but we will focus on date, datetime, time and timedelta. Let se see them one by one.
Formatting date time using strftime method and the documentation can be found here.
+
fromdatetimeimportdatetime
+# current date and time
+now=datetime.now()
+t=now.strftime("%H:%M:%S")
+print("time:",t)
+time_one=now.strftime("%m/%d/%Y, %H:%M:%S")
+# mm/dd/YY H:M:S format
+print("time one:",time_one)
+time_two=now.strftime("%d/%m/%Y, %H:%M:%S")
+# dd/mm/YY H:M:S format
+print("time two:",time_two)
+
today=date(year=2019,month=12,day=5)
+new_year=date(year=2020,month=1,day=1)
+time_left_for_newyear=new_year-today
+# Time left for new year: 27 days, 0:00:00
+print('Time left for new year: ',time_left_for_newyear)
+
+t1=datetime(year=2019,month=12,day=5,hour=0,minute=59,second=0)
+t2=datetime(year=2020,month=1,day=1,hour=0,minute=0,second=0)
+diff=t2-t1
+print('Time left for new year:',diff)# Time left for new year: 26 days, 23: 01: 00
+
+
Difference Between Two Points in Time Using timedelata⚓︎
+
+[<< Day 16](../16_Day_Python_date_time/16_python_datetime.md) | [Day 18 >>](../18_Day_Regular_expressions/18_regular_expressions.md)
+
+![30DaysOfPython](../images/30DaysOfPython_banner3@2x.png)
+
+- [📘 Day 17](#-day-17)
+ - [Exception Handling](#exception-handling)
+ - [Packing and Unpacking Arguments in Python](#packing-and-unpacking-arguments-in-python)
+ - [Unpacking](#unpacking)
+ - [Unpacking Lists](#unpacking-lists)
+ - [Unpacking Dictionaries](#unpacking-dictionaries)
+ - [Packing](#packing)
+ - [Packing Lists](#packing-lists)
+ - [Packing Dictionaries](#packing-dictionaries)
+ - [Spreading in Python](#spreading-in-python)
+ - [Enumerate](#enumerate)
+ - [Zip](#zip)
+ - [Exercises: Day 17](#exercises-day-17)
+
+# 📘 Day 17
+
+## Exception Handling
+
+Python uses _try_ and _except_ to handle errors gracefully. A graceful exit (or graceful handling) of errors is a simple programming idiom - a program detects a serious error condition and "exits gracefully", in a controlled manner as a result. Often the program prints a descriptive error message to a terminal or log as part of the graceful exit, this makes our application more robust. The cause of an exception is often external to the program itself. An example of exceptions could be an incorrect input, wrong file name, unable to find a file, a malfunctioning IO device. Graceful handling of errors prevents our applications from crashing.
+
+We have covered the different Python _error_ types in the previous section. If we use _try_ and _except_ in our program, then it will not raise errors in those blocks.
+
+![Try and Except](../images/try_except.png)
+
+```py
+try:
+ code in this block if things go well
+except:
+ code in this block run if things go wrong
+```
+
+**Example:**
+
+```py
+try:
+ print(10 + '5')
+except:
+ print('Something went wrong')
+```
+
+In the example above the second operand is a string. We could change it to float or int to add it with the number to make it work. But without any changes, the second block, _except_, will be executed.
+
+**Example:**
+
+```py
+try:
+ name = input('Enter your name:')
+ year_born = input('Year you were born:')
+ age = 2019 - year_born
+ print(f'You are {name}. And your age is {age}.')
+except:
+ print('Something went wrong')
+```
+
+```sh
+Something went wrong
+```
+
+In the above example, the exception block will run and we do not know exactly the problem. To analyze the problem, we can use the different error types with except.
+
+In the following example, it will handle the error and will also tell us the kind of error raised.
+
+```py
+try:
+ name = input('Enter your name:')
+ year_born = input('Year you were born:')
+ age = 2019 - year_born
+ print(f'You are {name}. And your age is {age}.')
+except TypeError:
+ print('Type error occured')
+except ValueError:
+ print('Value error occured')
+except ZeroDivisionError:
+ print('zero division error occured')
+```
+
+```sh
+Enter your name:Asabeneh
+Year you born:1920
+Type error occured
+```
+
+In the code above the output is going to be _TypeError_.
+Now, let's add an additional block:
+
+```py
+try:
+ name = input('Enter your name:')
+ year_born = input('Year you born:')
+ age = 2019 - int(year_born)
+ print('You are {name}. And your age is {age}.')
+except TypeError:
+ print('Type error occur')
+except ValueError:
+ print('Value error occur')
+except ZeroDivisionError:
+ print('zero division error occur')
+else:
+ print('I usually run with the try block')
+finally:
+ print('I alway run.')
+```
+
+```sh
+Enter your name:Asabeneh
+Year you born:1920
+You are Asabeneh. And your age is 99.
+I usually run with the try block
+I alway run.
+```
+
+It is also shorten the above code as follows:
+
+```py
+try:
+ name = input('Enter your name:')
+ year_born = input('Year you born:')
+ age = 2019 - int(year_born)
+ print('You are {name}. And your age is {age}.')
+except Exception as e:
+ print(e)
+
+```
+
+## Packing and Unpacking Arguments in Python
+
+We use two operators:
+
+- \* for tuples
+- \*\* for dictionaries
+
+Let us take as an example below. It takes only arguments but we have list. We can unpack the list and changes to argument.
+
+### Unpacking
+
+#### Unpacking Lists
+
+```py
+def sum_of_five_nums(a, b, c, d, e):
+ return a + b + c + d + e
+
+lst = [1, 2, 3, 4, 5]
+print(sum_of_five_nums(lst)) # TypeError: sum_of_five_nums() missing 4 required positional arguments: 'b', 'c', 'd', and 'e'
+```
+
+When we run the this code, it raises an error, because this function takes numbers (not a list) as arguments. Let us unpack/destructure the list.
+
+```py
+def sum_of_five_nums(a, b, c, d, e):
+ return a + b + c + d + e
+
+lst = [1, 2, 3, 4, 5]
+print(sum_of_five_nums(*lst)) # 15
+```
+
+We can also use unpacking in the range built-in function that expects a start and an end.
+
+```py
+numbers = range(2, 7) # normal call with separate arguments
+print(list(numbers)) # [2, 3, 4, 5, 6]
+args = [2, 7]
+numbers = range(*args) # call with arguments unpacked from a list
+print(numbers) # [2, 3, 4, 5,6]
+
+```
+
+A list or a tuple can also be unpacked like this:
+
+```py
+countries = ['Finland', 'Sweden', 'Norway', 'Denmark', 'Iceland']
+fin, sw, nor, *rest = countries
+print(fin, sw, nor, rest) # Finland Sweden Norway ['Denmark', 'Iceland']
+numbers = [1, 2, 3, 4, 5, 6, 7]
+one, *middle, last = numbers
+print(one, middle, last) # 1 [2, 3, 4, 5, 6] 7
+```
+
+#### Unpacking Dictionaries
+
+```py
+def unpacking_person_info(name, country, city, age):
+ return f'{name} lives in {country}, {city}. He is {age} year old.'
+dct = {'name':'Asabeneh', 'country':'Finland', 'city':'Helsinki', 'age':250}
+print(unpacking_person_info(**dct)) # Asabeneh lives in Finland, Helsinki. He is 250 years old.
+```
+
+### Packing
+
+Sometimes we never know how many arguments need to be passed to a python function. We can use the packing method to allow our function to take unlimited number or arbitrary number of arguments.
+
+### Packing Lists
+
+```py
+def sum_all(*args):
+ s = 0
+ for i in args:
+ s += i
+ return s
+print(sum_all(1, 2, 3)) # 6
+print(sum_all(1, 2, 3, 4, 5, 6, 7)) # 28
+```
+
+#### Packing Dictionaries
+
+```py
+def packing_person_info(**kwargs):
+ # check the type of kwargs and it is a dict type
+ # print(type(kwargs))
+ # Printing dictionary items
+ for key in kwargs:
+ print(f"{key} = {kwargs[key]}")
+ return kwargs
+
+print(packing_person_info(name="Asabeneh",
+ country="Finland", city="Helsinki", age=250))
+```
+
+```sh
+name = Asabeneh
+country = Finland
+city = Helsinki
+age = 250
+{'name': 'Asabeneh', 'country': 'Finland', 'city': 'Helsinki', 'age': 250}
+```
+
+## Spreading in Python
+
+Like in JavaScript, spreading is possible in Python. Let us check it in an example below:
+
+```py
+lst_one = [1, 2, 3]
+lst_two = [4, 5, 6, 7]
+lst = [0, *lst_one, *lst_two]
+print(lst) # [0, 1, 2, 3, 4, 5, 6, 7]
+country_lst_one = ['Finland', 'Sweden', 'Norway']
+country_lst_two = ['Denmark', 'Iceland']
+nordic_countries = [*country_lst_one, *country_lst_two]
+print(nordic_countries) # ['Finland', 'Sweden', 'Norway', 'Denmark', 'Iceland']
+```
+
+## Enumerate
+
+If we are interested in an index of a list, we use _enumerate_ built-in function to get the index of each item in the list.
+
+```py
+for index, item in enumerate([20, 30, 40]):
+ print(index, item)
+```
+
+```py
+for index, i in enumerate(countries):
+ print('hi')
+ if i == 'Finland':
+ print('The country {i} has been found at index {index}')
+```
+
+```sh
+The country Finland has been found at index 1.
+```
+
+## Zip
+
+Sometimes we would like to combine lists when looping through them. See the example below:
+
+```py
+fruits = ['banana', 'orange', 'mango', 'lemon', 'lime']
+vegetables = ['Tomato', 'Potato', 'Cabbage','Onion', 'Carrot']
+fruits_and_veges = []
+for f, v in zip(fruits, vegetables):
+ fruits_and_veges.append({'fruit':f, 'veg':v})
+
+print(fruits_and_veges)
+```
+
+```sh
+[{'fruit': 'banana', 'veg': 'Tomato'}, {'fruit': 'orange', 'veg': 'Potato'}, {'fruit': 'mango', 'veg': 'Cabbage'}, {'fruit': 'lemon', 'veg': 'Onion'}, {'fruit': 'lime', 'veg': 'Carrot'}]
+```
+
+🌕 You are determined. You are 17 steps a head to your way to greatness. Now do some exercises for your brain and muscles.
+
+## Exercises: Day 17
+
+1. names = ['Finland', 'Sweden', 'Norway','Denmark','Iceland', 'Estonia','Russia']. Unpack the first five countries and store them in a variable nordic_countries, store Estonia and Russia in es, and ru respectively.
+
+🎉 CONGRATULATIONS ! 🎉
+
+[<< Day 16](../16_Day_Python_date_time/16_python_datetime.md) | [Day 18 >>](../18_Day_Regular_expressions/18_regular_expressions.md)
diff --git a/17_exception_handling/index.html b/17_exception_handling/index.html
new file mode 100644
index 0000000..c1cd6a4
--- /dev/null
+++ b/17_exception_handling/index.html
@@ -0,0 +1,1614 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 17 exception handling - 30天入门Python全栈开发
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Python uses try and except to handle errors gracefully. A graceful exit (or graceful handling) of errors is a simple programming idiom - a program detects a serious error condition and "exits gracefully", in a controlled manner as a result. Often the program prints a descriptive error message to a terminal or log as part of the graceful exit, this makes our application more robust. The cause of an exception is often external to the program itself. An example of exceptions could be an incorrect input, wrong file name, unable to find a file, a malfunctioning IO device. Graceful handling of errors prevents our applications from crashing.
+
We have covered the different Python error types in the previous section. If we use try and except in our program, then it will not raise errors in those blocks.
try:
+ print(10+'5')
+except:
+ print('Something went wrong')
+
+
In the example above the second operand is a string. We could change it to float or int to add it with the number to make it work. But without any changes, the second block, except, will be executed.
+
Example:
+
try:
+ name=input('Enter your name:')
+ year_born=input('Year you were born:')
+ age=2019-year_born
+ print(f'You are {name}. And your age is {age}.')
+except:
+ print('Something went wrong')
+
+
Somethingwentwrong
+
+
In the above example, the exception block will run and we do not know exactly the problem. To analyze the problem, we can use the different error types with except.
+
In the following example, it will handle the error and will also tell us the kind of error raised.
+
try:
+ name=input('Enter your name:')
+ year_born=input('Year you were born:')
+ age=2019-year_born
+ print(f'You are {name}. And your age is {age}.')
+exceptTypeError:
+ print('Type error occured')
+exceptValueError:
+ print('Value error occured')
+exceptZeroDivisionError:
+ print('zero division error occured')
+
In the code above the output is going to be TypeError.
+Now, let's add an additional block:
+
try:
+ name=input('Enter your name:')
+ year_born=input('Year you born:')
+ age=2019-int(year_born)
+ print('You are {name}. And your age is {age}.')
+exceptTypeError:
+ print('Type error occur')
+exceptValueError:
+ print('Value error occur')
+exceptZeroDivisionError:
+ print('zero division error occur')
+else:
+ print('I usually run with the try block')
+finally:
+ print('I alway run.')
+
try:
+ name=input('Enter your name:')
+ year_born=input('Year you born:')
+ age=2019-int(year_born)
+ print('You are {name}. And your age is {age}.')
+exceptExceptionase:
+ print(e)
+
We can also use unpacking in the range built-in function that expects a start and an end.
+
numbers=range(2,7)# normal call with separate arguments
+print(list(numbers))# [2, 3, 4, 5, 6]
+args=[2,7]
+numbers=range(*args)# call with arguments unpacked from a list
+print(numbers)# [2, 3, 4, 5,6]
+
+
A list or a tuple can also be unpacked like this:
+
countries=['Finland','Sweden','Norway','Denmark','Iceland']
+fin,sw,nor,*rest=countries
+print(fin,sw,nor,rest)# Finland Sweden Norway ['Denmark', 'Iceland']
+numbers=[1,2,3,4,5,6,7]
+one,*middle,last=numbers
+print(one,middle,last)# 1 [2, 3, 4, 5, 6] 7
+
defunpacking_person_info(name,country,city,age):
+ returnf'{name} lives in {country}, {city}. He is {age} year old.'
+dct={'name':'Asabeneh','country':'Finland','city':'Helsinki','age':250}
+print(unpacking_person_info(**dct))# Asabeneh lives in Finland, Helsinki. He is 250 years old.
+
Sometimes we never know how many arguments need to be passed to a python function. We can use the packing method to allow our function to take unlimited number or arbitrary number of arguments.
defpacking_person_info(**kwargs):
+ # check the type of kwargs and it is a dict type
+ # print(type(kwargs))
+ # Printing dictionary items
+ forkeyinkwargs:
+ print(f"{key} = {kwargs[key]}")
+ returnkwargs
+
+print(packing_person_info(name="Asabeneh",
+ country="Finland",city="Helsinki",age=250))
+
names = ['Finland', 'Sweden', 'Norway','Denmark','Iceland', 'Estonia','Russia']. Unpack the first five countries and store them in a variable nordic_countries, store Estonia and Russia in es, and ru respectively.
+
+
+[<< Day 17](../17_Day_Exception_handling/17_exception_handling.md) | [Day 19>>](../19_Day_File_handling/19_file_handling.md)
+
+![30DaysOfPython](../images/30DaysOfPython_banner3@2x.png)
+
+- [📘 Day 18](#-day-18)
+ - [Regular Expressions](#regular-expressions)
+ - [The *re* Module](#the-re-module)
+ - [Methods in *re* Module](#methods-in-re-module)
+ - [Match](#match)
+ - [Search](#search)
+ - [Searching for All Matches Using *findall*](#searching-for-all-matches-using-findall)
+ - [Replacing a Substring](#replacing-a-substring)
+ - [Splitting Text Using RegEx Split](#splitting-text-using-regex-split)
+ - [Writing RegEx Patterns](#writing-regex-patterns)
+ - [Square Bracket](#square-bracket)
+ - [Escape character(\\) in RegEx](#escape-character-in-regex)
+ - [One or more times(+)](#one-or-more-times)
+ - [Period(.)](#period)
+ - [Zero or more times(\*)](#zero-or-more-times)
+ - [Zero or one time(?)](#zero-or-one-time)
+ - [Quantifier in RegEx](#quantifier-in-regex)
+ - [Cart ^](#cart-)
+ - [💻 Exercises: Day 18](#-exercises-day-18)
+ - [Exercises: Level 1](#exercises-level-1)
+ - [Exercises: Level 2](#exercises-level-2)
+ - [Exercises: Level 3](#exercises-level-3)
+
+# 📘 Day 18
+
+## Regular Expressions
+
+A regular expression or RegEx is a special text string that helps to find patterns in data. A RegEx can be used to check if some pattern exists in a different data type. To use RegEx in python first we should import the RegEx module which is called *re*.
+
+### The *re* Module
+
+After importing the module we can use it to detect or find patterns.
+
+```py
+import re
+```
+
+### Methods in *re* Module
+
+To find a pattern we use different set of *re* character sets that allows to search for a match in a string.
+
+- *re.match()*: searches only in the beginning of the first line of the string and returns matched objects if found, else returns None.
+- *re.search*: Returns a match object if there is one anywhere in the string, including multiline strings.
+- *re.findall*: Returns a list containing all matches
+- *re.split*: Takes a string, splits it at the match points, returns a list
+- *re.sub*: Replaces one or many matches within a string
+
+#### Match
+
+```py
+# syntac
+re.match(substring, string, re.I)
+# substring is a string or a pattern, string is the text we look for a pattern , re.I is case ignore
+```
+
+```py
+import re
+
+txt = 'I love to teach python and javaScript'
+# It returns an object with span, and match
+match = re.match('I love to teach', txt, re.I)
+print(match) #
+# We can get the starting and ending position of the match as tuple using span
+span = match.span()
+print(span) # (0, 15)
+# Lets find the start and stop position from the span
+start, end = span
+print(start, end) # 0, 15
+substring = txt[start:end]
+print(substring) # I love to teach
+```
+
+As you can see from the example above, the pattern we are looking for (or the substring we are looking for) is *I love to teach*. The match function returns an object **only** if the text starts with the pattern.
+
+```py
+import re
+
+txt = 'I love to teach python and javaScript'
+match = re.match('I like to teach', txt, re.I)
+print(match) # None
+```
+
+The string does not string with *I like to teach*, therefore there was no match and the match method returned None.
+
+#### Search
+
+```py
+# syntax
+re.match(substring, string, re.I)
+# substring is a pattern, string is the text we look for a pattern , re.I is case ignore flag
+```
+
+```py
+import re
+
+txt = '''Python is the most beautiful language that a human being has ever created.
+I recommend python for a first programming language'''
+
+# It returns an object with span and match
+match = re.search('first', txt, re.I)
+print(match) #
+# We can get the starting and ending position of the match as tuple using span
+span = match.span()
+print(span) # (100, 105)
+# Lets find the start and stop position from the span
+start, end = span
+print(start, end) # 100 105
+substring = txt[start:end]
+print(substring) # first
+```
+
+As you can see, search is much better than match because it can look for the pattern throughout the text. Search returns a match object with a first match that was found, otherwise it returns *None*. A much better *re* function is *findall*. This function checks for the pattern through the whole string and returns all the matches as a list.
+
+#### Searching for All Matches Using *findall*
+
+*findall()* returns all the matches as a list
+
+```py
+txt = '''Python is the most beautiful language that a human being has ever created.
+I recommend python for a first programming language'''
+
+# It return a list
+matches = re.findall('language', txt, re.I)
+print(matches) # ['language', 'language']
+```
+
+As you can see, the word *language* was found two times in the string. Let us practice some more.
+Now we will look for both Python and python words in the string:
+
+```py
+txt = '''Python is the most beautiful language that a human being has ever created.
+I recommend python for a first programming language'''
+
+# It returns list
+matches = re.findall('python', txt, re.I)
+print(matches) # ['Python', 'python']
+
+```
+
+Since we are using *re.I* both lowercase and uppercase letters are included. If we do not have the re.I flag, then we will have to write our pattern differently. Let us check it out:
+
+```py
+txt = '''Python is the most beautiful language that a human being has ever created.
+I recommend python for a first programming language'''
+
+matches = re.findall('Python|python', txt)
+print(matches) # ['Python', 'python']
+
+#
+matches = re.findall('[Pp]ython', txt)
+print(matches) # ['Python', 'python']
+
+```
+
+#### Replacing a Substring
+
+```py
+txt = '''Python is the most beautiful language that a human being has ever created.
+I recommend python for a first programming language'''
+
+match_replaced = re.sub('Python|python', 'JavaScript', txt, re.I)
+print(match_replaced) # JavaScript is the most beautiful language that a human being has ever created.
+# OR
+match_replaced = re.sub('[Pp]ython', 'JavaScript', txt, re.I)
+print(match_replaced) # JavaScript is the most beautiful language that a human being has ever created.
+```
+
+Let us add one more example. The following string is really hard to read unless we remove the % symbol. Replacing the % with an empty string will clean the text.
+
+```py
+
+txt = '''%I a%m te%%a%%che%r% a%n%d %% I l%o%ve te%ach%ing.
+T%he%re i%s n%o%th%ing as r%ewarding a%s e%duc%at%i%ng a%n%d e%m%p%ow%er%ing p%e%o%ple.
+I fo%und te%a%ching m%ore i%n%t%er%%es%ting t%h%an any other %jobs.
+D%o%es thi%s m%ot%iv%a%te %y%o%u to b%e a t%e%a%cher?'''
+
+matches = re.sub('%', '', txt)
+print(matches)
+```
+
+```sh
+I am teacher and I love teaching.
+There is nothing as rewarding as educating and empowering people.
+I found teaching more interesting than any other jobs. Does this motivate you to be a teacher?
+```
+
+## Splitting Text Using RegEx Split
+
+```py
+txt = '''I am teacher and I love teaching.
+There is nothing as rewarding as educating and empowering people.
+I found teaching more interesting than any other jobs.
+Does this motivate you to be a teacher?'''
+print(re.split('\n', txt)) # splitting using \n - end of line symbol
+```
+
+```sh
+['I am teacher and I love teaching.', 'There is nothing as rewarding as educating and empowering people.', 'I found teaching more interesting than any other jobs.', 'Does this motivate you to be a teacher?']
+```
+
+## Writing RegEx Patterns
+
+To declare a string variable we use a single or double quote. To declare RegEx variable *r''*.
+The following pattern only identifies apple with lowercase, to make it case insensitive either we should rewrite our pattern or we should add a flag.
+
+```py
+import re
+
+regex_pattern = r'apple'
+txt = 'Apple and banana are fruits. An old cliche says an apple a day a doctor way has been replaced by a banana a day keeps the doctor far far away. '
+matches = re.findall(regex_pattern, txt)
+print(matches) # ['apple']
+
+# To make case insensitive adding flag '
+matches = re.findall(regex_pattern, txt, re.I)
+print(matches) # ['Apple', 'apple']
+# or we can use a set of characters method
+regex_pattern = r'[Aa]pple' # this mean the first letter could be Apple or apple
+matches = re.findall(regex_pattern, txt)
+print(matches) # ['Apple', 'apple']
+
+```
+
+* []: A set of characters
+ - [a-c] means, a or b or c
+ - [a-z] means, any letter from a to z
+ - [A-Z] means, any character from A to Z
+ - [0-3] means, 0 or 1 or 2 or 3
+ - [0-9] means any number from 0 to 9
+ - [A-Za-z0-9] any single character, that is a to z, A to Z or 0 to 9
+- \\: uses to escape special characters
+ - \d means: match where the string contains digits (numbers from 0-9)
+ - \D means: match where the string does not contain digits
+- . : any character except new line character(\n)
+- ^: starts with
+ - r'^substring' eg r'^love', a sentence that starts with a word love
+ - r'[^abc] means not a, not b, not c.
+- $: ends with
+ - r'substring$' eg r'love$', sentence that ends with a word love
+- *: zero or more times
+ - r'[a]*' means a optional or it can occur many times.
+- +: one or more times
+ - r'[a]+' means at least once (or more)
+- ?: zero or one time
+ - r'[a]?' means zero times or once
+- {3}: Exactly 3 characters
+- {3,}: At least 3 characters
+- {3,8}: 3 to 8 characters
+- |: Either or
+ - r'apple|banana' means either apple or a banana
+- (): Capture and group
+
+![Regular Expression cheat sheet](../images/regex.png)
+
+Let us use examples to clarify the meta characters above
+
+### Square Bracket
+
+Let us use square bracket to include lower and upper case
+
+```py
+regex_pattern = r'[Aa]pple' # this square bracket mean either A or a
+txt = 'Apple and banana are fruits. An old cliche says an apple a day a doctor way has been replaced by a banana a day keeps the doctor far far away.'
+matches = re.findall(regex_pattern, txt)
+print(matches) # ['Apple', 'apple']
+```
+
+If we want to look for the banana, we write the pattern as follows:
+
+```py
+regex_pattern = r'[Aa]pple|[Bb]anana' # this square bracket means either A or a
+txt = 'Apple and banana are fruits. An old cliche says an apple a day a doctor way has been replaced by a banana a day keeps the doctor far far away.'
+matches = re.findall(regex_pattern, txt)
+print(matches) # ['Apple', 'banana', 'apple', 'banana']
+```
+
+Using the square bracket and or operator , we manage to extract Apple, apple, Banana and banana.
+
+### Escape character(\\) in RegEx
+
+```py
+regex_pattern = r'\d' # d is a special character which means digits
+txt = 'This regular expression example was made on December 6, 2019 and revised on July 8, 2021'
+matches = re.findall(regex_pattern, txt)
+print(matches) # ['6', '2', '0', '1', '9', '8', '2', '0', '2', '1'], this is not what we want
+```
+
+### One or more times(+)
+
+```py
+regex_pattern = r'\d+' # d is a special character which means digits, + mean one or more times
+txt = 'This regular expression example was made on December 6, 2019 and revised on July 8, 2021'
+matches = re.findall(regex_pattern, txt)
+print(matches) # ['6', '2019', '8', '2021'] - now, this is better!
+```
+
+### Period(.)
+
+```py
+regex_pattern = r'[a].' # this square bracket means a and . means any character except new line
+txt = '''Apple and banana are fruits'''
+matches = re.findall(regex_pattern, txt)
+print(matches) # ['an', 'an', 'an', 'a ', 'ar']
+
+regex_pattern = r'[a].+' # . any character, + any character one or more times
+matches = re.findall(regex_pattern, txt)
+print(matches) # ['and banana are fruits']
+```
+
+### Zero or more times(\*)
+
+Zero or many times. The pattern could may not occur or it can occur many times.
+
+```py
+regex_pattern = r'[a].*' # . any character, * any character zero or more times
+txt = '''Apple and banana are fruits'''
+matches = re.findall(regex_pattern, txt)
+print(matches) # ['and banana are fruits']
+```
+
+### Zero or one time(?)
+
+Zero or one time. The pattern may not occur or it may occur once.
+
+```py
+txt = '''I am not sure if there is a convention how to write the word e-mail.
+Some people write it as email others may write it as Email or E-mail.'''
+regex_pattern = r'[Ee]-?mail' # ? means here that '-' is optional
+matches = re.findall(regex_pattern, txt)
+print(matches) # ['e-mail', 'email', 'Email', 'E-mail']
+```
+
+### Quantifier in RegEx
+
+We can specify the length of the substring we are looking for in a text, using a curly bracket. Let us imagine, we are interested in a substring with a length of 4 characters:
+
+```py
+txt = 'This regular expression example was made on December 6, 2019 and revised on July 8, 2021'
+regex_pattern = r'\d{4}' # exactly four times
+matches = re.findall(regex_pattern, txt)
+print(matches) # ['2019', '2021']
+
+txt = 'This regular expression example was made on December 6, 2019 and revised on July 8, 2021'
+regex_pattern = r'\d{1, 4}' # 1 to 4
+matches = re.findall(regex_pattern, txt)
+print(matches) # ['6', '2019', '8', '2021']
+```
+
+### Cart ^
+
+- Starts with
+
+```py
+txt = 'This regular expression example was made on December 6, 2019 and revised on July 8, 2021'
+regex_pattern = r'^This' # ^ means starts with
+matches = re.findall(regex_pattern, txt)
+print(matches) # ['This']
+```
+
+- Negation
+
+```py
+txt = 'This regular expression example was made on December 6, 2019 and revised on July 8, 2021'
+regex_pattern = r'[^A-Za-z ]+' # ^ in set character means negation, not A to Z, not a to z, no space
+matches = re.findall(regex_pattern, txt)
+print(matches) # ['6,', '2019', '8', '2021']
+```
+
+## 💻 Exercises: Day 18
+
+### Exercises: Level 1
+
+ 1. What is the most frequent word in the following paragraph?
+
+```py
+ paragraph = 'I love teaching. If you do not love teaching what else can you love. I love Python if you do not love something which can give you all the capabilities to develop an application what else can you love.
+```
+
+```sh
+ [
+ (6, 'love'),
+ (5, 'you'),
+ (3, 'can'),
+ (2, 'what'),
+ (2, 'teaching'),
+ (2, 'not'),
+ (2, 'else'),
+ (2, 'do'),
+ (2, 'I'),
+ (1, 'which'),
+ (1, 'to'),
+ (1, 'the'),
+ (1, 'something'),
+ (1, 'if'),
+ (1, 'give'),
+ (1, 'develop'),
+ (1, 'capabilities'),
+ (1, 'application'),
+ (1, 'an'),
+ (1, 'all'),
+ (1, 'Python'),
+ (1, 'If')
+ ]
+```
+
+2. The position of some particles on the horizontal x-axis are -12, -4, -3 and -1 in the negative direction, 0 at origin, 4 and 8 in the positive direction. Extract these numbers from this whole text and find the distance between the two furthest particles.
+
+```py
+points = ['-12', '-4', '-3', '-1', '0', '4', '8']
+sorted_points = [-12, -4, -3, -1, -1, 0, 2, 4, 8]
+distance = 8 -(-12) # 20
+```
+
+### Exercises: Level 2
+
+1. Write a pattern which identifies if a string is a valid python variable
+
+ ```sh
+ is_valid_variable('first_name') # True
+ is_valid_variable('first-name') # False
+ is_valid_variable('1first_name') # False
+ is_valid_variable('firstname') # True
+ ```
+
+### Exercises: Level 3
+
+1. Clean the following text. After cleaning, count three most frequent words in the string.
+
+ ```py
+ sentence = '''%I $am@% a %tea@cher%, &and& I lo%#ve %tea@ching%;. There $is nothing; &as& mo@re rewarding as educa@ting &and& @emp%o@wering peo@ple. ;I found tea@ching m%o@re interesting tha@n any other %jo@bs. %Do@es thi%s mo@tivate yo@u to be a tea@cher!?'''
+
+ print(clean_text(sentence));
+ I am a teacher and I love teaching There is nothing as more rewarding as educating and empowering people I found teaching more interesting than any other jobs Does this motivate you to be a teacher
+ print(most_frequent_words(cleaned_text)) # [(3, 'I'), (2, 'teaching'), (2, 'teacher')]
+ ```
+
+🎉 CONGRATULATIONS ! 🎉
+
+[<< Day 17](../17_Day_Exception_handling/17_exception_handling.md) | [Day 19>>](../19_Day_File_handling/19_file_handling.md)
diff --git a/18_regular_expressions/index.html b/18_regular_expressions/index.html
new file mode 100644
index 0000000..aae1507
--- /dev/null
+++ b/18_regular_expressions/index.html
@@ -0,0 +1,1930 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 18 regular expressions - 30天入门Python全栈开发
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
A regular expression or RegEx is a special text string that helps to find patterns in data. A RegEx can be used to check if some pattern exists in a different data type. To use RegEx in python first we should import the RegEx module which is called re.
# syntac
+re.match(substring,string,re.I)
+# substring is a string or a pattern, string is the text we look for a pattern , re.I is case ignore
+
+
importre
+
+txt='I love to teach python and javaScript'
+# It returns an object with span, and match
+match=re.match('I love to teach',txt,re.I)
+print(match)# <re.Match object; span=(0, 15), match='I love to teach'>
+# We can get the starting and ending position of the match as tuple using span
+span=match.span()
+print(span)# (0, 15)
+# Lets find the start and stop position from the span
+start,end=span
+print(start,end)# 0, 15
+substring=txt[start:end]
+print(substring)# I love to teach
+
+
As you can see from the example above, the pattern we are looking for (or the substring we are looking for) is I love to teach. The match function returns an object only if the text starts with the pattern.
+
importre
+
+txt='I love to teach python and javaScript'
+match=re.match('I like to teach',txt,re.I)
+print(match)# None
+
+
The string does not string with I like to teach, therefore there was no match and the match method returned None.
# syntax
+re.match(substring,string,re.I)
+# substring is a pattern, string is the text we look for a pattern , re.I is case ignore flag
+
+
importre
+
+txt='''Python is the most beautiful language that a human being has ever created.
+I recommend python for a first programming language'''
+
+# It returns an object with span and match
+match=re.search('first',txt,re.I)
+print(match)# <re.Match object; span=(100, 105), match='first'>
+# We can get the starting and ending position of the match as tuple using span
+span=match.span()
+print(span)# (100, 105)
+# Lets find the start and stop position from the span
+start,end=span
+print(start,end)# 100 105
+substring=txt[start:end]
+print(substring)# first
+
+
As you can see, search is much better than match because it can look for the pattern throughout the text. Search returns a match object with a first match that was found, otherwise it returns None. A much better re function is findall. This function checks for the pattern through the whole string and returns all the matches as a list.
txt='''Python is the most beautiful language that a human being has ever created.
+I recommend python for a first programming language'''
+
+# It return a list
+matches=re.findall('language',txt,re.I)
+print(matches)# ['language', 'language']
+
+
As you can see, the word language was found two times in the string. Let us practice some more.
+Now we will look for both Python and python words in the string:
+
txt='''Python is the most beautiful language that a human being has ever created.
+I recommend python for a first programming language'''
+
+# It returns list
+matches=re.findall('python',txt,re.I)
+print(matches)# ['Python', 'python']
+
+
Since we are using re.I both lowercase and uppercase letters are included. If we do not have the re.I flag, then we will have to write our pattern differently. Let us check it out:
+
txt='''Python is the most beautiful language that a human being has ever created.
+I recommend python for a first programming language'''
+
+matches=re.findall('Python|python',txt)
+print(matches)# ['Python', 'python']
+
+#
+matches=re.findall('[Pp]ython',txt)
+print(matches)# ['Python', 'python']
+
txt='''Python is the most beautiful language that a human being has ever created.
+I recommend python for a first programming language'''
+
+match_replaced=re.sub('Python|python','JavaScript',txt,re.I)
+print(match_replaced)# JavaScript is the most beautiful language that a human being has ever created.
+# OR
+match_replaced=re.sub('[Pp]ython','JavaScript',txt,re.I)
+print(match_replaced)# JavaScript is the most beautiful language that a human being has ever created.
+
+
Let us add one more example. The following string is really hard to read unless we remove the % symbol. Replacing the % with an empty string will clean the text.
+
txt='''%I a%m te%%a%%che%r% a%n%d%% I l%o%ve te%ach%ing.
+T%he%re i%s n%o%th%ing as r%ewarding a%s e%duc%at%i%ng a%n%d e%m%p%ow%er%ing p%e%o%ple.
+I fo%und te%a%ching m%ore i%n%t%er%%es%ting t%h%an any other %jobs.
+D%o%es thi%s m%ot%iv%a%te %y%o%u to b%e a t%e%a%cher?'''
+
+matches=re.sub('%','',txt)
+print(matches)
+
txt='''I am teacher and I love teaching.
+There is nothing as rewarding as educating and empowering people.
+I found teaching more interesting than any other jobs.
+Does this motivate you to be a teacher?'''
+print(re.split('\n',txt))# splitting using \n - end of line symbol
+
+
['I am teacher and I love teaching.','There is nothing as rewarding as educating and empowering people.','I found teaching more interesting than any other jobs.','Does this motivate you to be a teacher?']
+
To declare a string variable we use a single or double quote. To declare RegEx variable r''.
+The following pattern only identifies apple with lowercase, to make it case insensitive either we should rewrite our pattern or we should add a flag.
+
importre
+
+regex_pattern=r'apple'
+txt='Apple and banana are fruits. An old cliche says an apple a day a doctor way has been replaced by a banana a day keeps the doctor far far away. '
+matches=re.findall(regex_pattern,txt)
+print(matches)# ['apple']
+
+# To make case insensitive adding flag '
+matches=re.findall(regex_pattern,txt,re.I)
+print(matches)# ['Apple', 'apple']
+# or we can use a set of characters method
+regex_pattern=r'[Aa]pple'# this mean the first letter could be Apple or apple
+matches=re.findall(regex_pattern,txt)
+print(matches)# ['Apple', 'apple']
+
+
+
[]: A set of characters
+
[a-c] means, a or b or c
+
[a-z] means, any letter from a to z
+
[A-Z] means, any character from A to Z
+
[0-3] means, 0 or 1 or 2 or 3
+
[0-9] means any number from 0 to 9
+
[A-Za-z0-9] any single character, that is a to z, A to Z or 0 to 9
+
\: uses to escape special characters
+
\d means: match where the string contains digits (numbers from 0-9)
+
\D means: match where the string does not contain digits
+
. : any character except new line character(\n)
+
^: starts with
+
r'^substring' eg r'^love', a sentence that starts with a word love
+
r'[^abc] means not a, not b, not c.
+
$: ends with
+
r'substring\(' eg r'love\)', sentence that ends with a word love
+
*: zero or more times
+
r'[a]*' means a optional or it can occur many times.
+
+: one or more times
+
r'[a]+' means at least once (or more)
+
?: zero or one time
+
r'[a]?' means zero times or once
+
{3}: Exactly 3 characters
+
{3,}: At least 3 characters
+
{3,8}: 3 to 8 characters
+
|: Either or
+
r'apple|banana' means either apple or a banana
+
(): Capture and group
+
+
+
Let us use examples to clarify the meta characters above
Let us use square bracket to include lower and upper case
+
regex_pattern=r'[Aa]pple'# this square bracket mean either A or a
+txt='Apple and banana are fruits. An old cliche says an apple a day a doctor way has been replaced by a banana a day keeps the doctor far far away.'
+matches=re.findall(regex_pattern,txt)
+print(matches)# ['Apple', 'apple']
+
+
If we want to look for the banana, we write the pattern as follows:
+
regex_pattern=r'[Aa]pple|[Bb]anana'# this square bracket means either A or a
+txt='Apple and banana are fruits. An old cliche says an apple a day a doctor way has been replaced by a banana a day keeps the doctor far far away.'
+matches=re.findall(regex_pattern,txt)
+print(matches)# ['Apple', 'banana', 'apple', 'banana']
+
+
Using the square bracket and or operator , we manage to extract Apple, apple, Banana and banana.
regex_pattern=r'\d'# d is a special character which means digits
+txt='This regular expression example was made on December 6, 2019 and revised on July 8, 2021'
+matches=re.findall(regex_pattern,txt)
+print(matches)# ['6', '2', '0', '1', '9', '8', '2', '0', '2', '1'], this is not what we want
+
regex_pattern=r'\d+'# d is a special character which means digits, + mean one or more times
+txt='This regular expression example was made on December 6, 2019 and revised on July 8, 2021'
+matches=re.findall(regex_pattern,txt)
+print(matches)# ['6', '2019', '8', '2021'] - now, this is better!
+
regex_pattern=r'[a].'# this square bracket means a and . means any character except new line
+txt='''Apple and banana are fruits'''
+matches=re.findall(regex_pattern,txt)
+print(matches)# ['an', 'an', 'an', 'a ', 'ar']
+
+regex_pattern=r'[a].+'# . any character, + any character one or more times
+matches=re.findall(regex_pattern,txt)
+print(matches)# ['and banana are fruits']
+
Zero or many times. The pattern could may not occur or it can occur many times.
+
regex_pattern=r'[a].*'# . any character, * any character zero or more times
+txt='''Apple and banana are fruits'''
+matches=re.findall(regex_pattern,txt)
+print(matches)# ['and banana are fruits']
+
Zero or one time. The pattern may not occur or it may occur once.
+
txt='''I am not sure if there is a convention how to write the word e-mail.
+Some people write it as email others may write it as Email or E-mail.'''
+regex_pattern=r'[Ee]-?mail'# ? means here that '-' is optional
+matches=re.findall(regex_pattern,txt)
+print(matches)# ['e-mail', 'email', 'Email', 'E-mail']
+
We can specify the length of the substring we are looking for in a text, using a curly bracket. Let us imagine, we are interested in a substring with a length of 4 characters:
+
txt='This regular expression example was made on December 6, 2019 and revised on July 8, 2021'
+regex_pattern=r'\d{4}'# exactly four times
+matches=re.findall(regex_pattern,txt)
+print(matches)# ['2019', '2021']
+
+txt='This regular expression example was made on December 6, 2019 and revised on July 8, 2021'
+regex_pattern=r'\d{1, 4}'# 1 to 4
+matches=re.findall(regex_pattern,txt)
+print(matches)# ['6', '2019', '8', '2021']
+
txt='This regular expression example was made on December 6, 2019 and revised on July 8, 2021'
+regex_pattern=r'^This'# ^ means starts with
+matches=re.findall(regex_pattern,txt)
+print(matches)# ['This']
+
+
+
Negation
+
+
txt='This regular expression example was made on December 6, 2019 and revised on July 8, 2021'
+regex_pattern=r'[^A-Za-z ]+'# ^ in set character means negation, not A to Z, not a to z, no space
+matches=re.findall(regex_pattern,txt)
+print(matches)# ['6,', '2019', '8', '2021']
+
What is the most frequent word in the following paragraph?
+
+
paragraph='I love teaching. If you do not love teaching what else can you love. I love Python if you do not love something which can give you all the capabilities to develop an application what else can you love.
+
The position of some particles on the horizontal x-axis are -12, -4, -3 and -1 in the negative direction, 0 at origin, 4 and 8 in the positive direction. Extract these numbers from this whole text and find the distance between the two furthest particles.
Clean the following text. After cleaning, count three most frequent words in the string.
+
sentence='''%I $am@% a %tea@cher%, &and& I lo%#ve %tea@ching%;. There $is nothing; &as& mo@re rewarding as educa@ting &and& @emp%o@wering peo@ple. ;I found tea@ching m%o@re interesting tha@n any other %jo@bs. %Do@es thi%s mo@tivate yo@u to be a tea@cher!?'''
+
+print(clean_text(sentence));
+IamateacherandIloveteachingThereisnothingasmorerewardingaseducatingandempoweringpeopleIfoundteachingmoreinterestingthananyotherjobsDoesthismotivateyoutobeateacher
+print(most_frequent_words(cleaned_text))# [(3, 'I'), (2, 'teaching'), (2, 'teacher')]
+
+
+[<< Day 18](../18_Day_Regular_expressions/18_regular_expressions.md) | [Day 20 >>](../20_Day_Python_package_manager/20_python_package_manager.md)
+
+![30DaysOfPython](../images/30DaysOfPython_banner3@2x.png)
+
+- [📘 Day 19](#-day-19)
+ - [File Handling](#file-handling)
+ - [Opening Files for Reading](#opening-files-for-reading)
+ - [Opening Files for Writing and Updating](#opening-files-for-writing-and-updating)
+ - [Deleting Files](#deleting-files)
+ - [File Types](#file-types)
+ - [File with txt Extension](#file-with-txt-extension)
+ - [File with json Extension](#file-with-json-extension)
+ - [Changing JSON to Dictionary](#changing-json-to-dictionary)
+ - [Changing Dictionary to JSON](#changing-dictionary-to-json)
+ - [Saving as JSON File](#saving-as-json-file)
+ - [File with csv Extension](#file-with-csv-extension)
+ - [File with xlsx Extension](#file-with-xlsx-extension)
+ - [File with xml Extension](#file-with-xml-extension)
+ - [💻 Exercises: Day 19](#-exercises-day-19)
+ - [Exercises: Level 1](#exercises-level-1)
+ - [Exercises: Level 2](#exercises-level-2)
+ - [Exercises: Level 3](#exercises-level-3)
+
+# 📘 Day 19
+
+## File Handling
+
+So far we have seen different Python data types. We usually store our data in different file formats. In addition to handling files, we will also see different file formats(.txt, .json, .xml, .csv, .tsv, .excel) in this section. First, let us get familiar with handling files with common file format(.txt).
+
+File handling is an import part of programming which allows us to create, read, update and delete files. In Python to handle data we use _open()_ built-in function.
+
+```py
+# Syntax
+open('filename', mode) # mode(r, a, w, x, t,b) could be to read, write, update
+```
+
+- "r" - Read - Default value. Opens a file for reading, it returns an error if the file does not exist
+- "a" - Append - Opens a file for appending, creates the file if it does not exist
+- "w" - Write - Opens a file for writing, creates the file if it does not exist
+- "x" - Create - Creates the specified file, returns an error if the file exists
+- "t" - Text - Default value. Text mode
+- "b" - Binary - Binary mode (e.g. images)
+
+### Opening Files for Reading
+
+The default mode of _open_ is reading, so we do not have to specify 'r' or 'rt'. I have created and saved a file named reading_file_example.txt in the files directory. Let us see how it is done:
+
+```py
+f = open('./files/reading_file_example.txt')
+print(f) # <_io.TextIOWrapper name='./files/reading_file_example.txt' mode='r' encoding='UTF-8'>
+```
+
+As you can see in the example above, I printed the opened file and it gave some information about it. Opened file has different reading methods: _read()_, _readline_, _readlines_. An opened file has to be closed with _close()_ method.
+
+- _read()_: read the whole text as string. If we want to limit the number of characters we want to read, we can limit it by passing int value to the *read(number)* method.
+
+```py
+f = open('./files/reading_file_example.txt')
+txt = f.read()
+print(type(txt))
+print(txt)
+f.close()
+```
+
+```sh
+# output
+
+This is an example to show how to open a file and read.
+This is the second line of the text.
+```
+
+Instead of printing all the text, let us print the first 10 characters of the text file.
+
+```py
+f = open('./files/reading_file_example.txt')
+txt = f.read(10)
+print(type(txt))
+print(txt)
+f.close()
+```
+
+```sh
+# output
+
+This is an
+```
+
+- _readline()_: read only the first line
+
+```py
+f = open('./files/reading_file_example.txt')
+line = f.readline()
+print(type(line))
+print(line)
+f.close()
+```
+
+```sh
+# output
+
+This is an example to show how to open a file and read.
+```
+
+- _readlines()_: read all the text line by line and returns a list of lines
+
+```py
+f = open('./files/reading_file_example.txt')
+lines = f.readlines()
+print(type(lines))
+print(lines)
+f.close()
+```
+
+```sh
+# output
+
+['This is an example to show how to open a file and read.\n', 'This is the second line of the text.']
+```
+
+Another way to get all the lines as a list is using _splitlines()_:
+
+```py
+f = open('./files/reading_file_example.txt')
+lines = f.read().splitlines()
+print(type(lines))
+print(lines)
+f.close()
+```
+
+```sh
+# output
+
+['This is an example to show how to open a file and read.', 'This is the second line of the text.']
+```
+
+After we open a file, we should close it. There is a high tendency of forgetting to close them. There is a new way of opening files using _with_ - closes the files by itself. Let us rewrite the the previous example with the _with_ method:
+
+```py
+with open('./files/reading_file_example.txt') as f:
+ lines = f.read().splitlines()
+ print(type(lines))
+ print(lines)
+```
+
+```sh
+# output
+
+['This is an example to show how to open a file and read.', 'This is the second line of the text.']
+```
+
+### Opening Files for Writing and Updating
+
+To write to an existing file, we must add a mode as parameter to the _open()_ function:
+
+- "a" - append - will append to the end of the file, if the file does not it creates a new file.
+- "w" - write - will overwrite any existing content, if the file does not exist it creates.
+
+Let us append some text to the file we have been reading:
+
+```py
+with open('./files/reading_file_example.txt','a') as f:
+ f.write('This text has to be appended at the end')
+```
+
+The method below creates a new file, if the file does not exist:
+
+```py
+with open('./files/writing_file_example.txt','w') as f:
+ f.write('This text will be written in a newly created file')
+```
+
+### Deleting Files
+
+We have seen in previous section, how to make and remove a directory using _os_ module. Again now, if we want to remove a file we use _os_ module.
+
+```py
+import os
+os.remove('./files/example.txt')
+
+```
+
+If the file does not exist, the remove method will raise an error, so it is good to use a condition like this:
+
+```py
+import os
+if os.path.exists('./files/example.txt'):
+ os.remove('./files/example.txt')
+else:
+ print('The file does not exist')
+```
+
+## File Types
+
+### File with txt Extension
+
+File with _txt_ extension is a very common form of data and we have covered it in the previous section. Let us move to the JSON file
+
+### File with json Extension
+
+JSON stands for JavaScript Object Notation. Actually, it is a stringified JavaScript object or Python dictionary.
+
+_Example:_
+
+```py
+# dictionary
+person_dct= {
+ "name":"Asabeneh",
+ "country":"Finland",
+ "city":"Helsinki",
+ "skills":["JavaScrip", "React","Python"]
+}
+# JSON: A string form a dictionary
+person_json = "{'name': 'Asabeneh', 'country': 'Finland', 'city': 'Helsinki', 'skills': ['JavaScrip', 'React', 'Python']}"
+
+# we use three quotes and make it multiple line to make it more readable
+person_json = '''{
+ "name":"Asabeneh",
+ "country":"Finland",
+ "city":"Helsinki",
+ "skills":["JavaScrip", "React","Python"]
+}'''
+```
+
+### Changing JSON to Dictionary
+
+To change a JSON to a dictionary, first we import the json module and then we use _loads_ method.
+
+```py
+import json
+# JSON
+person_json = '''{
+ "name": "Asabeneh",
+ "country": "Finland",
+ "city": "Helsinki",
+ "skills": ["JavaScrip", "React", "Python"]
+}'''
+# let's change JSON to dictionary
+person_dct = json.loads(person_json)
+print(type(person_dct))
+print(person_dct)
+print(person_dct['name'])
+```
+
+```sh
+# output
+
+{'name': 'Asabeneh', 'country': 'Finland', 'city': 'Helsinki', 'skills': ['JavaScrip', 'React', 'Python']}
+Asabeneh
+```
+
+### Changing Dictionary to JSON
+
+To change a dictionary to a JSON we use _dumps_ method from the json module.
+
+```py
+import json
+# python dictionary
+person = {
+ "name": "Asabeneh",
+ "country": "Finland",
+ "city": "Helsinki",
+ "skills": ["JavaScrip", "React", "Python"]
+}
+# let's convert it to json
+person_json = json.dumps(person, indent=4) # indent could be 2, 4, 8. It beautifies the json
+print(type(person_json))
+print(person_json)
+```
+
+```sh
+# output
+# when you print it, it does not have the quote, but actually it is a string
+# JSON does not have type, it is a string type.
+
+{
+ "name": "Asabeneh",
+ "country": "Finland",
+ "city": "Helsinki",
+ "skills": [
+ "JavaScrip",
+ "React",
+ "Python"
+ ]
+}
+```
+
+### Saving as JSON File
+
+We can also save our data as a json file. Let us save it as a json file using the following steps. For writing a json file, we use the json.dump() method, it can take dictionary, output file, ensure_ascii and indent.
+
+```py
+import json
+# python dictionary
+person = {
+ "name": "Asabeneh",
+ "country": "Finland",
+ "city": "Helsinki",
+ "skills": ["JavaScrip", "React", "Python"]
+}
+with open('./files/json_example.json', 'w', encoding='utf-8') as f:
+ json.dump(person, f, ensure_ascii=False, indent=4)
+```
+
+In the code above, we use encoding and indentation. Indentation makes the json file easy to read.
+
+### File with csv Extension
+
+CSV stands for comma separated values. CSV is a simple file format used to store tabular data, such as a spreadsheet or database. CSV is a very common data format in data science.
+
+**Example:**
+
+```csv
+"name","country","city","skills"
+"Asabeneh","Finland","Helsinki","JavaScript"
+```
+
+**Example:**
+
+```py
+import csv
+with open('./files/csv_example.csv') as f:
+ csv_reader = csv.reader(f, delimiter=',') # w use, reader method to read csv
+ line_count = 0
+ for row in csv_reader:
+ if line_count == 0:
+ print(f'Column names are :{", ".join(row)}')
+ line_count += 1
+ else:
+ print(
+ f'\t{row[0]} is a teachers. He lives in {row[1]}, {row[2]}.')
+ line_count += 1
+ print(f'Number of lines: {line_count}')
+```
+
+```sh
+# output:
+Column names are :name, country, city, skills
+ Asabeneh is a teacher. He lives in Finland, Helsinki.
+Number of lines: 2
+```
+
+### File with xlsx Extension
+
+To read excel files we need to install _xlrd_ package. We will cover this after we cover package installing using pip.
+
+```py
+import xlrd
+excel_book = xlrd.open_workbook('sample.xls)
+print(excel_book.nsheets)
+print(excel_book.sheet_names)
+```
+
+### File with xml Extension
+
+XML is another structured data format which looks like HTML. In XML the tags are not predefined. The first line is an XML declaration. The person tag is the root of the XML. The person has a gender attribute.
+**Example:XML**
+
+```xml
+
+
+ Asabeneh
+ Finland
+ Helsinki
+
+ JavaScrip
+ React
+ Python
+
+
+```
+
+For more information on how to read an XML file check the [documentation](https://docs.python.org/2/library/xml.etree.elementtree.html)
+
+```py
+import xml.etree.ElementTree as ET
+tree = ET.parse('./files/xml_example.xml')
+root = tree.getroot()
+print('Root tag:', root.tag)
+print('Attribute:', root.attrib)
+for child in root:
+ print('field: ', child.tag)
+```
+
+```sh
+# output
+Root tag: person
+Attribute: {'gender': 'male'}
+field: name
+field: country
+field: city
+field: skills
+```
+
+🌕 You are making a big progress. Maintain your momentum, keep the good work. Now do some exercises for your brain and muscles.
+
+## 💻 Exercises: Day 19
+
+### Exercises: Level 1
+
+1. Write a function which count number of lines and number of words in a text. All the files are in the data the folder:
+ a) Read obama_speech.txt file and count number of lines and words
+ b) Read michelle_obama_speech.txt file and count number of lines and words
+ c) Read donald_speech.txt file and count number of lines and words
+ d) Read melina_trump_speech.txt file and count number of lines and words
+2. Read the countries_data.json data file in data directory, create a function that finds the ten most spoken languages
+
+ ```py
+ # Your output should look like this
+ print(most_spoken_languages(filename='./data/countries_data.json', 10))
+ [(91, 'English'),
+ (45, 'French'),
+ (25, 'Arabic'),
+ (24, 'Spanish'),
+ (9, 'Russian'),
+ (9, 'Portuguese'),
+ (8, 'Dutch'),
+ (7, 'German'),
+ (5, 'Chinese'),
+ (4, 'Swahili'),
+ (4, 'Serbian')]
+
+ # Your output should look like this
+ print(most_spoken_languages(filename='./data/countries_data.json', 3))
+ [(91, 'English'),
+ (45, 'French'),
+ (25, 'Arabic')]
+ ```
+
+3. Read the countries_data.json data file in data directory, create a function that creates a list of the ten most populated countries
+
+ ```py
+ # Your output should look like this
+ print(most_populated_countries(filename='./data/countries_data.json', 10))
+
+ [
+ {'country': 'China', 'population': 1377422166},
+ {'country': 'India', 'population': 1295210000},
+ {'country': 'United States of America', 'population': 323947000},
+ {'country': 'Indonesia', 'population': 258705000},
+ {'country': 'Brazil', 'population': 206135893},
+ {'country': 'Pakistan', 'population': 194125062},
+ {'country': 'Nigeria', 'population': 186988000},
+ {'country': 'Bangladesh', 'population': 161006790},
+ {'country': 'Russian Federation', 'population': 146599183},
+ {'country': 'Japan', 'population': 126960000}
+ ]
+
+ # Your output should look like this
+
+ print(most_populated_countries(filename='./data/countries_data.json', 3))
+ [
+ {'country': 'China', 'population': 1377422166},
+ {'country': 'India', 'population': 1295210000},
+ {'country': 'United States of America', 'population': 323947000}
+ ]
+ ```
+
+### Exercises: Level 2
+
+4. Extract all incoming email addresses as a list from the email_exchange_big.txt file.
+5. Find the most common words in the English language. Call the name of your function find_most_common_words, it will take two parameters - a string or a file and a positive integer, indicating the number of words. Your function will return an array of tuples in descending order. Check the output
+
+```py
+ # Your output should look like this
+ print(find_most_common_words('sample.txt', 10))
+ [(10, 'the'),
+ (8, 'be'),
+ (6, 'to'),
+ (6, 'of'),
+ (5, 'and'),
+ (4, 'a'),
+ (4, 'in'),
+ (3, 'that'),
+ (2, 'have'),
+ (2, 'I')]
+
+ # Your output should look like this
+ print(find_most_common_words('sample.txt', 5))
+
+ [(10, 'the'),
+ (8, 'be'),
+ (6, 'to'),
+ (6, 'of'),
+ (5, 'and')]
+```
+
+6. Use the function, find_most_frequent_words to find:
+ a) The ten most frequent words used in [Obama's speech](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/obama_speech.txt)
+ b) The ten most frequent words used in [Michelle's speech](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/michelle_obama_speech.txt)
+ c) The ten most frequent words used in [Trump's speech](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/donald_speech.txt)
+ d) The ten most frequent words used in [Melina's speech](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/melina_trump_speech.txt)
+7. Write a python application that checks similarity between two texts. It takes a file or a string as a parameter and it will evaluate the similarity of the two texts. For instance check the similarity between the transcripts of [Michelle's](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/michelle_obama_speech.txt) and [Melina's](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/melina_trump_speech.txt) speech. You may need a couple of functions, function to clean the text(clean_text), function to remove support words(remove_support_words) and finally to check the similarity(check_text_similarity). List of [stop words](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/stop_words.py) are in the data directory
+8. Find the 10 most repeated words in the romeo_and_juliet.txt
+9. Read the [hacker news csv](https://github.com/Asabeneh/30-Days-Of-Python/blob/master/data/hacker_news.csv) file and find out:
+ a) Count the number of lines containing python or Python
+ b) Count the number lines containing JavaScript, javascript or Javascript
+ c) Count the number lines containing Java and not JavaScript
+
+### Exercises: Level 3
+
+🎉 CONGRATULATIONS ! 🎉
+
+[<< Day 18](../18_Day_Regular_expressions/18_regular_expressions.md) | [Day 20 >>](../20_Day_Python_package_manager/20_python_package_manager.md)
diff --git a/19_file_handling/index.html b/19_file_handling/index.html
new file mode 100644
index 0000000..5ba7ffc
--- /dev/null
+++ b/19_file_handling/index.html
@@ -0,0 +1,1894 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 19 file handling - 30天入门Python全栈开发
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
So far we have seen different Python data types. We usually store our data in different file formats. In addition to handling files, we will also see different file formats(.txt, .json, .xml, .csv, .tsv, .excel) in this section. First, let us get familiar with handling files with common file format(.txt).
+
File handling is an import part of programming which allows us to create, read, update and delete files. In Python to handle data we use open() built-in function.
+
# Syntax
+open('filename',mode)# mode(r, a, w, x, t,b) could be to read, write, update
+
+
+
"r" - Read - Default value. Opens a file for reading, it returns an error if the file does not exist
+
"a" - Append - Opens a file for appending, creates the file if it does not exist
+
"w" - Write - Opens a file for writing, creates the file if it does not exist
+
"x" - Create - Creates the specified file, returns an error if the file exists
The default mode of open is reading, so we do not have to specify 'r' or 'rt'. I have created and saved a file named reading_file_example.txt in the files directory. Let us see how it is done:
As you can see in the example above, I printed the opened file and it gave some information about it. Opened file has different reading methods: read(), readline, readlines. An opened file has to be closed with close() method.
+
+
read(): read the whole text as string. If we want to limit the number of characters we want to read, we can limit it by passing int value to the read(number) method.
# output
+<class'list'>
+['This is an example to show how to open a file and read.','This is the second line of the text.']
+
+
After we open a file, we should close it. There is a high tendency of forgetting to close them. There is a new way of opening files using with - closes the files by itself. Let us rewrite the the previous example with the with method:
JSON stands for JavaScript Object Notation. Actually, it is a stringified JavaScript object or Python dictionary.
+
Example:
+
# dictionary
+person_dct={
+ "name":"Asabeneh",
+ "country":"Finland",
+ "city":"Helsinki",
+ "skills":["JavaScrip","React","Python"]
+}
+# JSON: A string form a dictionary
+person_json="{'name': 'Asabeneh', 'country': 'Finland', 'city': 'Helsinki', 'skills': ['JavaScrip', 'React', 'Python']}"
+
+# we use three quotes and make it multiple line to make it more readable
+person_json='''{
+ "name":"Asabeneh",
+ "country":"Finland",
+ "city":"Helsinki",
+ "skills":["JavaScrip", "React","Python"]
+}'''
+
To change a dictionary to a JSON we use dumps method from the json module.
+
importjson
+# python dictionary
+person={
+ "name":"Asabeneh",
+ "country":"Finland",
+ "city":"Helsinki",
+ "skills":["JavaScrip","React","Python"]
+}
+# let's convert it to json
+person_json=json.dumps(person,indent=4)# indent could be 2, 4, 8. It beautifies the json
+print(type(person_json))
+print(person_json)
+
+
# output
+# when you print it, it does not have the quote, but actually it is a string
+# JSON does not have type, it is a string type.
+<class'str'>
+{
+"name":"Asabeneh",
+"country":"Finland",
+"city":"Helsinki",
+"skills":[
+"JavaScrip",
+"React",
+"Python"
+]
+}
+
We can also save our data as a json file. Let us save it as a json file using the following steps. For writing a json file, we use the json.dump() method, it can take dictionary, output file, ensure_ascii and indent.
CSV stands for comma separated values. CSV is a simple file format used to store tabular data, such as a spreadsheet or database. CSV is a very common data format in data science.
XML is another structured data format which looks like HTML. In XML the tags are not predefined. The first line is an XML declaration. The person tag is the root of the XML. The person has a gender attribute.
+Example:XML
Write a function which count number of lines and number of words in a text. All the files are in the data the folder:
+ a) Read obama_speech.txt file and count number of lines and words
+ b) Read michelle_obama_speech.txt file and count number of lines and words
+ c) Read donald_speech.txt file and count number of lines and words
+ d) Read melina_trump_speech.txt file and count number of lines and words
+
Read the countries_data.json data file in data directory, create a function that finds the ten most spoken languages
+
+
# Your output should look like this
+print(most_spoken_languages(filename='./data/countries_data.json',10))
+[(91,'English'),
+(45,'French'),
+(25,'Arabic'),
+(24,'Spanish'),
+(9,'Russian'),
+(9,'Portuguese'),
+(8,'Dutch'),
+(7,'German'),
+(5,'Chinese'),
+(4,'Swahili'),
+(4,'Serbian')]
+
+# Your output should look like this
+print(most_spoken_languages(filename='./data/countries_data.json',3))
+[(91,'English'),
+(45,'French'),
+(25,'Arabic')]
+
+
+
Read the countries_data.json data file in data directory, create a function that creates a list of the ten most populated countries
+
+
# Your output should look like this
+print(most_populated_countries(filename='./data/countries_data.json',10))
+
+[
+{'country':'China','population':1377422166},
+{'country':'India','population':1295210000},
+{'country':'United States of America','population':323947000},
+{'country':'Indonesia','population':258705000},
+{'country':'Brazil','population':206135893},
+{'country':'Pakistan','population':194125062},
+{'country':'Nigeria','population':186988000},
+{'country':'Bangladesh','population':161006790},
+{'country':'Russian Federation','population':146599183},
+{'country':'Japan','population':126960000}
+]
+
+# Your output should look like this
+
+print(most_populated_countries(filename='./data/countries_data.json',3))
+[
+{'country':'China','population':1377422166},
+{'country':'India','population':1295210000},
+{'country':'United States of America','population':323947000}
+]
+
Extract all incoming email addresses as a list from the email_exchange_big.txt file.
+
Find the most common words in the English language. Call the name of your function find_most_common_words, it will take two parameters - a string or a file and a positive integer, indicating the number of words. Your function will return an array of tuples in descending order. Check the output
+
+
# Your output should look like this
+ print(find_most_common_words('sample.txt',10))
+ [(10,'the'),
+ (8,'be'),
+ (6,'to'),
+ (6,'of'),
+ (5,'and'),
+ (4,'a'),
+ (4,'in'),
+ (3,'that'),
+ (2,'have'),
+ (2,'I')]
+
+ # Your output should look like this
+ print(find_most_common_words('sample.txt',5))
+
+ [(10,'the'),
+ (8,'be'),
+ (6,'to'),
+ (6,'of'),
+ (5,'and')]
+
+
+
Use the function, find_most_frequent_words to find:
+ a) The ten most frequent words used in Obama's speech
+ b) The ten most frequent words used in Michelle's speech
+ c) The ten most frequent words used in Trump's speech
+ d) The ten most frequent words used in Melina's speech
+
Write a python application that checks similarity between two texts. It takes a file or a string as a parameter and it will evaluate the similarity of the two texts. For instance check the similarity between the transcripts of Michelle's and Melina's speech. You may need a couple of functions, function to clean the text(clean_text), function to remove support words(remove_support_words) and finally to check the similarity(check_text_similarity). List of stop words are in the data directory
+
Find the 10 most repeated words in the romeo_and_juliet.txt
+
Read the hacker news csv file and find out:
+ a) Count the number of lines containing python or Python
+ b) Count the number lines containing JavaScript, javascript or Javascript
+ c) Count the number lines containing Java and not JavaScript
+
+[<< Day 19](../19_Day_File_handling/19_file_handling.md) | [Day 21 >>](../21_Day_Classes_and_objects/21_classes_and_objects.md)
+
+![30DaysOfPython](../images/30DaysOfPython_banner3@2x.png)
+
+- [📘 Day 20](#-day-20)
+ - [Python PIP - Python Package Manager](#python-pip---python-package-manager)
+ - [What is PIP ?](#what-is-pip-)
+ - [Installing PIP](#installing-pip)
+ - [Installing packages using pip](#installing-packages-using-pip)
+ - [Uninstalling Packages](#uninstalling-packages)
+ - [List of Packages](#list-of-packages)
+ - [Show Package](#show-package)
+ - [PIP Freeze](#pip-freeze)
+ - [Reading from URL](#reading-from-url)
+ - [Creating a Package](#creating-a-package)
+ - [Further Information About Packages](#further-information-about-packages)
+ - [Exercises: Day 20](#exercises-day-20)
+
+# 📘 Day 20
+
+## Python PIP - Python Package Manager
+
+### What is PIP ?
+
+PIP stands for Preferred installer program. We use _pip_ to install different Python packages.
+Package is a Python module that can contain one or more modules or other packages. A module or modules that we can install to our application is a package.
+In programming, we do not have to write every utility program, instead we install packages and import them to our applications.
+
+### Installing PIP
+
+If you did not install pip, let us install it now. Go to your terminal or command prompt and copy and paste this:
+
+```sh
+asabeneh@Asabeneh:~$ pip install pip
+```
+
+Check if pip is installed by writing
+
+```sh
+pip --version
+```
+
+```py
+asabeneh@Asabeneh:~$ pip --version
+pip 21.1.3 from /usr/local/lib/python3.7/site-packages/pip (python 3.9.6)
+```
+
+As you can see, I am using pip version 21.1.3, if you see some number a bit below or above that, means you have pip installed.
+
+Let us check some of the packages used in the Python community for different purposes. Just to let you know that there are lots of packages available for use with different applications.
+
+### Installing packages using pip
+
+Let us try to install _numpy_, called numeric python. It is one of the most popular packages in machine learning and data science community.
+
+- NumPy is the fundamental package for scientific computing with Python. It contains among other things:
+ - a powerful N-dimensional array object
+ - sophisticated (broadcasting) functions
+ - tools for integrating C/C++ and Fortran code
+ - useful linear algebra, Fourier transform, and random number capabilities
+
+```sh
+asabeneh@Asabeneh:~$ pip install numpy
+```
+
+Let us start using numpy. Open your python interactive shell, write python and then import numpy as follows:
+
+```py
+asabeneh@Asabeneh:~$ python
+Python 3.9.6 (default, Jun 28 2021, 15:26:21)
+[Clang 11.0.0 (clang-1100.0.33.8)] on darwin
+Type "help", "copyright", "credits" or "license" for more information.
+>>> import numpy
+>>> numpy.version.version
+'1.20.1'
+>>> lst = [1, 2, 3,4, 5]
+>>> np_arr = numpy.array(lst)
+>>> np_arr
+array([1, 2, 3, 4, 5])
+>>> len(np_arr)
+5
+>>> np_arr * 2
+array([ 2, 4, 6, 8, 10])
+>>> np_arr + 2
+array([3, 4, 5, 6, 7])
+>>>
+```
+
+Pandas is an open source, BSD-licensed library providing high-performance, easy-to-use data structures and data analysis tools for the Python programming language. Let us install the big brother of numpy, _pandas_:
+
+```sh
+asabeneh@Asabeneh:~$ pip install pandas
+```
+
+```py
+asabeneh@Asabeneh:~$ python
+Python 3.9.6 (default, Jun 28 2021, 15:26:21)
+[Clang 11.0.0 (clang-1100.0.33.8)] on darwin
+Type "help", "copyright", "credits" or "license" for more information.
+>>> import pandas
+```
+
+This section is not about numpy nor pandas, here we are trying to learn how to install packages and how to import them. If it is needed, we will talk about different packages in other sections.
+
+Let us import a web browser module, which can help us to open any website. We do not need to install this module, it is already installed by default with Python 3. For instance if you like to open any number of websites at any time or if you like to schedule something, this _webbrowser_ module can be used.
+
+```py
+import webbrowser # web browser module to open websites
+
+# list of urls: python
+url_lists = [
+ 'http://www.python.org',
+ 'https://www.linkedin.com/in/asabeneh/',
+ 'https://github.com/Asabeneh',
+ 'https://twitter.com/Asabeneh',
+]
+
+# opens the above list of websites in a different tab
+for url in url_lists:
+ webbrowser.open_new_tab(url)
+```
+
+### Uninstalling Packages
+
+If you do not like to keep the installed packages, you can remove them using the following command.
+
+```sh
+pip uninstall packagename
+```
+
+### List of Packages
+
+To see the installed packages on our machine. We can use pip followed by list.
+
+```sh
+pip list
+```
+
+### Show Package
+
+To show information about a package
+
+```sh
+pip show packagename
+```
+
+```sh
+asabeneh@Asabeneh:~$ pip show pandas
+Name: pandas
+Version: 1.2.3
+Summary: Powerful data structures for data analysis, time series, and statistics
+Home-page: http://pandas.pydata.org
+Author: None
+Author-email: None
+License: BSD
+Location: /usr/local/lib/python3.7/site-packages
+Requires: python-dateutil, pytz, numpy
+Required-by:
+```
+
+If we want even more details, just add --verbose
+
+```sh
+asabeneh@Asabeneh:~$ pip show --verbose pandas
+Name: pandas
+Version: 1.2.3
+Summary: Powerful data structures for data analysis, time series, and statistics
+Home-page: http://pandas.pydata.org
+Author: None
+Author-email: None
+License: BSD
+Location: /usr/local/lib/python3.7/site-packages
+Requires: numpy, pytz, python-dateutil
+Required-by:
+Metadata-Version: 2.1
+Installer: pip
+Classifiers:
+ Development Status :: 5 - Production/Stable
+ Environment :: Console
+ Operating System :: OS Independent
+ Intended Audience :: Science/Research
+ Programming Language :: Python
+ Programming Language :: Python :: 3
+ Programming Language :: Python :: 3.5
+ Programming Language :: Python :: 3.6
+ Programming Language :: Python :: 3.7
+ Programming Language :: Python :: 3.8
+ Programming Language :: Cython
+ Topic :: Scientific/Engineering
+Entry-points:
+ [pandas_plotting_backends]
+ matplotlib = pandas:plotting._matplotlib
+```
+
+### PIP Freeze
+
+Generate installed Python packages with their version and the output is suitable to use it in a requirements file. A requirements.txt file is a file that should contain all the installed Python packages in a Python project.
+
+```sh
+asabeneh@Asabeneh:~$ pip freeze
+docutils==0.11
+Jinja2==2.7.2
+MarkupSafe==0.19
+Pygments==1.6
+Sphinx==1.2.2
+```
+
+The pip freeze gave us the packages used, installed and their version. We use it with requirements.txt file for deployment.
+
+### Reading from URL
+
+By now you are familiar with how to read or write on a file located on you local machine. Sometimes, we would like to read from a website using url or from an API.
+API stands for Application Program Interface. It is a means to exchange structured data between servers primarily as json data. To open a network connection, we need a package called _requests_ - it allows to open a network connection and to implement CRUD(create, read, update and delete) operations. In this section, we will cover only reading ore getting part of a CRUD.
+
+Let us install _requests_:
+
+```py
+asabeneh@Asabeneh:~$ pip install requests
+```
+
+We will see _get_, _status_code_, _headers_, _text_ and _json_ methods in _requests_ module:
+ - _get()_: to open a network and fetch data from url - it returns a response object
+ - _status_code_: After we fetched data, we can check the status of the operation (success, error, etc)
+ - _headers_: To check the header types
+ - _text_: to extract the text from the fetched response object
+ - _json_: to extract json data
+Let's read a txt file from this website, https://www.w3.org/TR/PNG/iso_8859-1.txt.
+
+```py
+import requests # importing the request module
+
+url = 'https://www.w3.org/TR/PNG/iso_8859-1.txt' # text from a website
+
+response = requests.get(url) # opening a network and fetching a data
+print(response)
+print(response.status_code) # status code, success:200
+print(response.headers) # headers information
+print(response.text) # gives all the text from the page
+```
+
+```sh
+
+200
+{'date': 'Sun, 08 Dec 2019 18:00:31 GMT', 'last-modified': 'Fri, 07 Nov 2003 05:51:11 GMT', 'etag': '"17e9-3cb82080711c0;50c0b26855880-gzip"', 'accept-ranges': 'bytes', 'cache-control': 'max-age=31536000', 'expires': 'Mon, 07 Dec 2020 18:00:31 GMT', 'vary': 'Accept-Encoding', 'content-encoding': 'gzip', 'access-control-allow-origin': '*', 'content-length': '1616', 'content-type': 'text/plain', 'strict-transport-security': 'max-age=15552000; includeSubdomains; preload', 'content-security-policy': 'upgrade-insecure-requests'}
+```
+
+- Let us read from an API. API stands for Application Program Interface. It is a means to exchange structure data between servers primarily a json data. An example of an API:https://restcountries.eu/rest/v2/all. Let us read this API using _requests_ module.
+
+```py
+import requests
+url = 'https://restcountries.eu/rest/v2/all' # countries api
+response = requests.get(url) # opening a network and fetching a data
+print(response) # response object
+print(response.status_code) # status code, success:200
+countries = response.json()
+print(countries[:1]) # we sliced only the first country, remove the slicing to see all countries
+```
+
+```sh
+
+200
+[{'alpha2Code': 'AF',
+ 'alpha3Code': 'AFG',
+ 'altSpellings': ['AF', 'Afġānistān'],
+ 'area': 652230.0,
+ 'borders': ['IRN', 'PAK', 'TKM', 'UZB', 'TJK', 'CHN'],
+ 'callingCodes': ['93'],
+ 'capital': 'Kabul',
+ 'cioc': 'AFG',
+ 'currencies': [{'code': 'AFN', 'name': 'Afghan afghani', 'symbol': '؋'}],
+ 'demonym': 'Afghan',
+ 'flag': 'https://restcountries.eu/data/afg.svg',
+ 'gini': 27.8,
+ 'languages': [{'iso639_1': 'ps',
+ 'iso639_2': 'pus',
+ 'name': 'Pashto',
+ 'nativeName': 'پښتو'},
+ {'iso639_1': 'uz',
+ 'iso639_2': 'uzb',
+ 'name': 'Uzbek',
+ 'nativeName': 'Oʻzbek'},
+ {'iso639_1': 'tk',
+ 'iso639_2': 'tuk',
+ 'name': 'Turkmen',
+ 'nativeName': 'Türkmen'}],
+ 'latlng': [33.0, 65.0],
+ 'name': 'Afghanistan',
+ 'nativeName': 'افغانستان',
+ 'numericCode': '004',
+ 'population': 27657145,
+ 'region': 'Asia',
+ 'regionalBlocs': [{'acronym': 'SAARC',
+ 'name': 'South Asian Association for Regional Cooperation',
+ 'otherAcronyms': [],
+ 'otherNames': []}],
+ 'subregion': 'Southern Asia',
+ 'timezones': ['UTC+04:30'],
+ 'topLevelDomain': ['.af'],
+ 'translations': {'br': 'Afeganistão',
+ 'de': 'Afghanistan',
+ 'es': 'Afganistán',
+ 'fa': 'افغانستان',
+ 'fr': 'Afghanistan',
+ 'hr': 'Afganistan',
+ 'it': 'Afghanistan',
+ 'ja': 'アフガニスタン',
+ 'nl': 'Afghanistan',
+ 'pt': 'Afeganistão'}}]
+```
+
+We use _json()_ method from response object, if the we are fetching JSON data. For txt, html, xml and other file formats we can use _text_.
+
+### Creating a Package
+
+We organize a large number of files in different folders and sub-folders based on some criteria, so that we can find and manage them easily. As you know, a module can contain multiple objects, such as classes, functions, etc. A package can contain one or more relevant modules. A package is actually a folder containing one or more module files. Let us create a package named mypackage, using the following steps:
+
+Create a new folder named mypacakge inside 30DaysOfPython folder
+Create an empty **__init__**.py file in the mypackage folder.
+Create modules arithmetic.py and greet.py with following code:
+
+```py
+# mypackage/arithmetics.py
+# arithmetics.py
+def add_numbers(*args):
+ total = 0
+ for num in args:
+ total += num
+ return total
+
+
+def subtract(a, b):
+ return (a - b)
+
+
+def multiple(a, b):
+ return a * b
+
+
+def division(a, b):
+ return a / b
+
+
+def remainder(a, b):
+ return a % b
+
+
+def power(a, b):
+ return a ** b
+```
+
+```py
+# mypackage/greet.py
+# greet.py
+def greet_person(firstname, lastname):
+ return f'{firstname} {lastname}, welcome to 30DaysOfPython Challenge!'
+```
+
+The folder structure of your package should look like this:
+
+```sh
+─ mypackage
+ ├── __init__.py
+ ├── arithmetic.py
+ └── greet.py
+```
+
+Now let's open the python interactive shell and try the package we have created:
+
+```sh
+asabeneh@Asabeneh:~/Desktop/30DaysOfPython$ python
+Python 3.9.6 (default, Jun 28 2021, 15:26:21)
+[Clang 11.0.0 (clang-1100.0.33.8)] on darwin
+Type "help", "copyright", "credits" or "license" for more information.
+>>> from mypackage import arithmetics
+>>> arithmetics.add_numbers(1, 2, 3, 5)
+11
+>>> arithmetics.subtract(5, 3)
+2
+>>> arithmetics.multiple(5, 3)
+15
+>>> arithmetics.division(5, 3)
+1.6666666666666667
+>>> arithmetics.remainder(5, 3)
+2
+>>> arithmetics.power(5, 3)
+125
+>>> from mypackage import greet
+>>> greet.greet_person('Asabeneh', 'Yetayeh')
+'Asabeneh Yetayeh, welcome to 30DaysOfPython Challenge!'
+>>>
+```
+
+As you can see our package works perfectly. The package folder contains a special file called **__init__**.py - it stores the package's content. If we put **__init__**.py in the package folder, python start recognizes it as a package.
+The **__init__**.py exposes specified resources from its modules to be imported to other python files. An empty **__init__**.py file makes all functions available when a package is imported. The **__init__**.py is essential for the folder to be recognized by Python as a package.
+
+### Further Information About Packages
+
+- Database
+ - SQLAlchemy or SQLObject - Object oriented access to several different database systems
+ - _pip install SQLAlchemy_
+- Web Development
+ - Django - High-level web framework.
+ - _pip install django_
+ - Flask - micro framework for Python based on Werkzeug, Jinja 2. (It's BSD licensed)
+ - _pip install flask_
+- HTML Parser
+ - [Beautiful Soup](https://www.crummy.com/software/BeautifulSoup/bs4/doc/) - HTML/XML parser designed for quick turnaround projects like screen-scraping, will accept bad markup.
+ - _pip install beautifulsoup4_
+ - PyQuery - implements jQuery in Python; faster than BeautifulSoup, apparently.
+
+- XML Processing
+ - ElementTree - The Element type is a simple but flexible container object, designed to store hierarchical data structures, such as simplified XML infosets, in memory. --Note: Python 2.5 and up has ElementTree in the Standard Library
+- GUI
+ - PyQt - Bindings for the cross-platform Qt framework.
+ - TkInter - The traditional Python user interface toolkit.
+- Data Analysis, Data Science and Machine learning
+ - Numpy: Numpy(numeric python) is known as one of the most popular machine learning library in Python.
+ - Pandas: is a data analysis, data science and a machine learning library in Python that provides data structures of high-level and a wide variety of tools for analysis.
+ - SciPy: SciPy is a machine learning library for application developers and engineers. SciPy library contains modules for optimization, linear algebra, integration, image processing, and statistics.
+ - Scikit-Learn: It is NumPy and SciPy. It is considered as one of the best libraries for working with complex data.
+ - TensorFlow: is a machine learning library built by Google.
+ - Keras: is considered as one of the coolest machine learning libraries in Python. It provides an easier mechanism to express neural networks. Keras also provides some of the best utilities for compiling models, processing data-sets, visualization of graphs, and much more.
+- Network:
+ - requests: is a package which we can use to send requests to a server(GET, POST, DELETE, PUT)
+ - _pip install requests_
+
+🌕 You are always progressing and you are a head of 20 steps to your way to greatness. Now do some exercises for your brain and muscles.
+
+## Exercises: Day 20
+
+1. Read this url and find the 10 most frequent words. romeo_and_juliet = 'http://www.gutenberg.org/files/1112/1112.txt'
+2. Read the cats API and cats_api = 'https://api.thecatapi.com/v1/breeds' and find :
+ 1. the min, max, mean, median, standard deviation of cats' weight in metric units.
+ 2. the min, max, mean, median, standard deviation of cats' lifespan in years.
+ 3. Create a frequency table of country and breed of cats
+3. Read the [countries API](https://restcountries.eu/rest/v2/all) and find
+ 1. the 10 largest countries
+ 2. the 10 most spoken languages
+ 3. the total number of languages in the countries API
+4. UCI is one of the most common places to get data sets for data science and machine learning. Read the content of UCL (https://archive.ics.uci.edu/ml/datasets.php). Without additional libraries it will be difficult, so you may try it with BeautifulSoup4
+
+🎉 CONGRATULATIONS ! 🎉
+
+[<< Day 19](../19_Day_File_handling/19_file_handling.md) | [Day 21 >>](../21_Day_Classes_and_objects/21_classes_and_objects.md)
diff --git a/20_python_package_manager/index.html b/20_python_package_manager/index.html
new file mode 100644
index 0000000..1b4081f
--- /dev/null
+++ b/20_python_package_manager/index.html
@@ -0,0 +1,1754 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 20 python package manager - 30天入门Python全栈开发
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
PIP stands for Preferred installer program. We use pip to install different Python packages.
+Package is a Python module that can contain one or more modules or other packages. A module or modules that we can install to our application is a package.
+In programming, we do not have to write every utility program, instead we install packages and import them to our applications.
As you can see, I am using pip version 21.1.3, if you see some number a bit below or above that, means you have pip installed.
+
Let us check some of the packages used in the Python community for different purposes. Just to let you know that there are lots of packages available for use with different applications.
Pandas is an open source, BSD-licensed library providing high-performance, easy-to-use data structures and data analysis tools for the Python programming language. Let us install the big brother of numpy, pandas:
This section is not about numpy nor pandas, here we are trying to learn how to install packages and how to import them. If it is needed, we will talk about different packages in other sections.
+
Let us import a web browser module, which can help us to open any website. We do not need to install this module, it is already installed by default with Python 3. For instance if you like to open any number of websites at any time or if you like to schedule something, this webbrowser module can be used.
+
importwebbrowser# web browser module to open websites
+
+# list of urls: python
+url_lists=[
+ 'http://www.python.org',
+ 'https://www.linkedin.com/in/asabeneh/',
+ 'https://github.com/Asabeneh',
+ 'https://twitter.com/Asabeneh',
+]
+
+# opens the above list of websites in a different tab
+forurlinurl_lists:
+ webbrowser.open_new_tab(url)
+
Generate installed Python packages with their version and the output is suitable to use it in a requirements file. A requirements.txt file is a file that should contain all the installed Python packages in a Python project.
By now you are familiar with how to read or write on a file located on you local machine. Sometimes, we would like to read from a website using url or from an API.
+API stands for Application Program Interface. It is a means to exchange structured data between servers primarily as json data. To open a network connection, we need a package called requests - it allows to open a network connection and to implement CRUD(create, read, update and delete) operations. In this section, we will cover only reading ore getting part of a CRUD.
+
Let us install requests:
+
asabeneh@Asabeneh:~$pipinstallrequests
+
+
We will see get, status_code, headers, text and json methods in requests module:
+ - get(): to open a network and fetch data from url - it returns a response object
+ - status_code: After we fetched data, we can check the status of the operation (success, error, etc)
+ - headers: To check the header types
+ - text: to extract the text from the fetched response object
+ - json: to extract json data
+Let's read a txt file from this website, https://www.w3.org/TR/PNG/iso_8859-1.txt.
+
importrequests# importing the request module
+
+url='https://www.w3.org/TR/PNG/iso_8859-1.txt'# text from a website
+
+response=requests.get(url)# opening a network and fetching a data
+print(response)
+print(response.status_code)# status code, success:200
+print(response.headers)# headers information
+print(response.text)# gives all the text from the page
+
+
<Response[200]>
+200
+{'date':'Sun, 08 Dec 2019 18:00:31 GMT','last-modified':'Fri, 07 Nov 2003 05:51:11 GMT','etag':'"17e9-3cb82080711c0;50c0b26855880-gzip"','accept-ranges':'bytes','cache-control':'max-age=31536000','expires':'Mon, 07 Dec 2020 18:00:31 GMT','vary':'Accept-Encoding','content-encoding':'gzip','access-control-allow-origin':'*','content-length':'1616','content-type':'text/plain','strict-transport-security':'max-age=15552000; includeSubdomains; preload','content-security-policy':'upgrade-insecure-requests'}
+
+
+
Let us read from an API. API stands for Application Program Interface. It is a means to exchange structure data between servers primarily a json data. An example of an API:https://restcountries.eu/rest/v2/all. Let us read this API using requests module.
+
+
importrequests
+url='https://restcountries.eu/rest/v2/all'# countries api
+response=requests.get(url)# opening a network and fetching a data
+print(response)# response object
+print(response.status_code)# status code, success:200
+countries=response.json()
+print(countries[:1])# we sliced only the first country, remove the slicing to see all countries
+
We organize a large number of files in different folders and sub-folders based on some criteria, so that we can find and manage them easily. As you know, a module can contain multiple objects, such as classes, functions, etc. A package can contain one or more relevant modules. A package is actually a folder containing one or more module files. Let us create a package named mypackage, using the following steps:
+
Create a new folder named mypacakge inside 30DaysOfPython folder
+Create an empty init.py file in the mypackage folder.
+Create modules arithmetic.py and greet.py with following code:
As you can see our package works perfectly. The package folder contains a special file called init.py - it stores the package's content. If we put init.py in the package folder, python start recognizes it as a package.
+The init.py exposes specified resources from its modules to be imported to other python files. An empty init.py file makes all functions available when a package is imported. The init.py is essential for the folder to be recognized by Python as a package.
SQLAlchemy or SQLObject - Object oriented access to several different database systems
+
pip install SQLAlchemy
+
+
+
Web Development
+
Django - High-level web framework.
+
pip install django
+
+
+
Flask - micro framework for Python based on Werkzeug, Jinja 2. (It's BSD licensed)
+
pip install flask
+
+
+
HTML Parser
+
Beautiful Soup - HTML/XML parser designed for quick turnaround projects like screen-scraping, will accept bad markup.
+
pip install beautifulsoup4
+
+
+
+
PyQuery - implements jQuery in Python; faster than BeautifulSoup, apparently.
+
+
+
XML Processing
+
+
ElementTree - The Element type is a simple but flexible container object, designed to store hierarchical data structures, such as simplified XML infosets, in memory. --Note: Python 2.5 and up has ElementTree in the Standard Library
+
GUI
+
PyQt - Bindings for the cross-platform Qt framework.
+
TkInter - The traditional Python user interface toolkit.
+
Data Analysis, Data Science and Machine learning
+
Numpy: Numpy(numeric python) is known as one of the most popular machine learning library in Python.
+
Pandas: is a data analysis, data science and a machine learning library in Python that provides data structures of high-level and a wide variety of tools for analysis.
+
SciPy: SciPy is a machine learning library for application developers and engineers. SciPy library contains modules for optimization, linear algebra, integration, image processing, and statistics.
+
Scikit-Learn: It is NumPy and SciPy. It is considered as one of the best libraries for working with complex data.
+
TensorFlow: is a machine learning library built by Google.
+
Keras: is considered as one of the coolest machine learning libraries in Python. It provides an easier mechanism to express neural networks. Keras also provides some of the best utilities for compiling models, processing data-sets, visualization of graphs, and much more.
+
Network:
+
requests: is a package which we can use to send requests to a server(GET, POST, DELETE, PUT)
+
pip install requests
+
+
+
+
🌕 You are always progressing and you are a head of 20 steps to your way to greatness. Now do some exercises for your brain and muscles.
the total number of languages in the countries API
+
UCI is one of the most common places to get data sets for data science and machine learning. Read the content of UCL (https://archive.ics.uci.edu/ml/datasets.php). Without additional libraries it will be difficult, so you may try it with BeautifulSoup4
+
+[<< Day 20](../20_Day_Python_package_manager/20_python_package_manager.md) | [Day 22 >>](../22_Day_Web_scraping/22_web_scraping.md)
+
+![30DaysOfPython](../images/30DaysOfPython_banner3@2x.png)
+
+- [📘 Day 21](#-day-21)
+ - [Classes and Objects](#classes-and-objects)
+ - [Creating a Class](#creating-a-class)
+ - [Creating an Object](#creating-an-object)
+ - [Class Constructor](#class-constructor)
+ - [Object Methods](#object-methods)
+ - [Object Default Methods](#object-default-methods)
+ - [Method to Modify Class Default Values](#method-to-modify-class-default-values)
+ - [Inheritance](#inheritance)
+ - [Overriding parent method](#overriding-parent-method)
+ - [💻 Exercises: Day 21](#-exercises-day-21)
+ - [Exercises: Level 1](#exercises-level-1)
+ - [Exercises: Level 2](#exercises-level-2)
+ - [Exercises: Level 3](#exercises-level-3)
+
+# 📘 Day 21
+
+## Classes and Objects
+
+Python is an object oriented programming language. Everything in Python is an object, with its properties and methods. A number, string, list, dictionary, tuple, set etc. used in a program is an object of a corresponding built-in class. We create class to create an object. A class is like an object constructor, or a "blueprint" for creating objects. We instantiate a class to create an object. The class defines attributes and the behavior of the object, while the object, on the other hand, represents the class.
+
+We have been working with classes and objects right from the beginning of this challenge unknowingly. Every element in a Python program is an object of a class.
+Let us check if everything in python is a class:
+
+```py
+asabeneh@Asabeneh:~$ python
+Python 3.9.6 (default, Jun 28 2021, 15:26:21)
+[Clang 11.0.0 (clang-1100.0.33.8)] on darwin
+Type "help", "copyright", "credits" or "license" for more information.
+>>> num = 10
+>>> type(num)
+
+>>> string = 'string'
+>>> type(string)
+
+>>> boolean = True
+>>> type(boolean)
+
+>>> lst = []
+>>> type(lst)
+
+>>> tpl = ()
+>>> type(tpl)
+
+>>> set1 = set()
+>>> type(set1)
+
+>>> dct = {}
+>>> type(dct)
+
+```
+
+### Creating a Class
+
+To create a class we need the key word **class** followed by the name and colon. Class name should be **CamelCase**.
+
+```sh
+# syntax
+class ClassName:
+ code goes here
+```
+
+**Example:**
+
+```py
+class Person:
+ pass
+print(Person)
+```
+
+```sh
+<__main__.Person object at 0x10804e510>
+```
+
+### Creating an Object
+
+We can create an object by calling the class.
+
+```py
+p = Person()
+print(p)
+```
+
+### Class Constructor
+
+In the examples above, we have created an object from the Person class. However, a class without a constructor is not really useful in real applications. Let us use constructor function to make our class more useful. Like the constructor function in Java or JavaScript, Python has also a built-in **__init__**() constructor function. The **__init__** constructor function has self parameter which is a reference to the current instance of the class
+**Examples:**
+
+```py
+class Person:
+ def __init__ (self, name):
+ # self allows to attach parameter to the class
+ self.name =name
+
+p = Person('Asabeneh')
+print(p.name)
+print(p)
+```
+
+```sh
+# output
+Asabeneh
+<__main__.Person object at 0x2abf46907e80>
+```
+
+Let us add more parameters to the constructor function.
+
+```py
+class Person:
+ def __init__(self, firstname, lastname, age, country, city):
+ self.firstname = firstname
+ self.lastname = lastname
+ self.age = age
+ self.country = country
+ self.city = city
+
+
+p = Person('Asabeneh', 'Yetayeh', 250, 'Finland', 'Helsinki')
+print(p.firstname)
+print(p.lastname)
+print(p.age)
+print(p.country)
+print(p.city)
+```
+
+```sh
+# output
+Asabeneh
+Yetayeh
+250
+Finland
+Helsinki
+```
+
+### Object Methods
+
+Objects can have methods. The methods are functions which belong to the object.
+
+**Example:**
+
+```py
+class Person:
+ def __init__(self, firstname, lastname, age, country, city):
+ self.firstname = firstname
+ self.lastname = lastname
+ self.age = age
+ self.country = country
+ self.city = city
+ def person_info(self):
+ return f'{self.firstname} {self.lastname} is {self.age} years old. He lives in {self.city}, {self.country}'
+
+p = Person('Asabeneh', 'Yetayeh', 250, 'Finland', 'Helsinki')
+print(p.person_info())
+```
+
+```sh
+# output
+Asabeneh Yetayeh is 250 years old. He lives in Helsinki, Finland
+```
+
+### Object Default Methods
+
+Sometimes, you may want to have a default values for your object methods. If we give default values for the parameters in the constructor, we can avoid errors when we call or instantiate our class without parameters. Let's see how it looks:
+
+**Example:**
+
+```py
+class Person:
+ def __init__(self, firstname='Asabeneh', lastname='Yetayeh', age=250, country='Finland', city='Helsinki'):
+ self.firstname = firstname
+ self.lastname = lastname
+ self.age = age
+ self.country = country
+ self.city = city
+
+ def person_info(self):
+ return f'{self.firstname} {self.lastname} is {self.age} years old. He lives in {self.city}, {self.country}.'
+
+p1 = Person()
+print(p1.person_info())
+p2 = Person('John', 'Doe', 30, 'Nomanland', 'Noman city')
+print(p2.person_info())
+```
+
+```sh
+# output
+Asabeneh Yetayeh is 250 years old. He lives in Helsinki, Finland.
+John Doe is 30 years old. He lives in Noman city, Nomanland.
+```
+
+### Method to Modify Class Default Values
+
+In the example below, the person class, all the constructor parameters have default values. In addition to that, we have skills parameter, which we can access using a method. Let us create add_skill method to add skills to the skills list.
+
+```py
+class Person:
+ def __init__(self, firstname='Asabeneh', lastname='Yetayeh', age=250, country='Finland', city='Helsinki'):
+ self.firstname = firstname
+ self.lastname = lastname
+ self.age = age
+ self.country = country
+ self.city = city
+ self.skills = []
+
+ def person_info(self):
+ return f'{self.firstname} {self.lastname} is {self.age} years old. He lives in {self.city}, {self.country}.'
+ def add_skill(self, skill):
+ self.skills.append(skill)
+
+p1 = Person()
+print(p1.person_info())
+p1.add_skill('HTML')
+p1.add_skill('CSS')
+p1.add_skill('JavaScript')
+p2 = Person('John', 'Doe', 30, 'Nomanland', 'Noman city')
+print(p2.person_info())
+print(p1.skills)
+print(p2.skills)
+```
+
+```sh
+# output
+Asabeneh Yetayeh is 250 years old. He lives in Helsinki, Finland.
+John Doe is 30 years old. He lives in Noman city, Nomanland.
+['HTML', 'CSS', 'JavaScript']
+[]
+```
+
+### Inheritance
+
+Using inheritance we can reuse parent class code. Inheritance allows us to define a class that inherits all the methods and properties from parent class. The parent class or super or base class is the class which gives all the methods and properties. Child class is the class that inherits from another or parent class.
+Let us create a student class by inheriting from person class.
+
+```py
+class Student(Person):
+ pass
+
+
+s1 = Student('Eyob', 'Yetayeh', 30, 'Finland', 'Helsinki')
+s2 = Student('Lidiya', 'Teklemariam', 28, 'Finland', 'Espoo')
+print(s1.person_info())
+s1.add_skill('JavaScript')
+s1.add_skill('React')
+s1.add_skill('Python')
+print(s1.skills)
+
+print(s2.person_info())
+s2.add_skill('Organizing')
+s2.add_skill('Marketing')
+s2.add_skill('Digital Marketing')
+print(s2.skills)
+
+```
+
+```sh
+output
+Eyob Yetayeh is 30 years old. He lives in Helsinki, Finland.
+['JavaScript', 'React', 'Python']
+Lidiya Teklemariam is 28 years old. He lives in Espoo, Finland.
+['Organizing', 'Marketing', 'Digital Marketing']
+```
+
+We did not call the **__init__**() constructor in the child class. If we didn't call it then we can still access all the properties from the parent. But if we do call the constructor we can access the parent properties by calling _super_.
+We can add a new method to the child or we can override the parent class methods by creating the same method name in the child class. When we add the **__init__**() function, the child class will no longer inherit the parent's **__init__**() function.
+
+### Overriding parent method
+
+```py
+class Student(Person):
+ def __init__ (self, firstname='Asabeneh', lastname='Yetayeh',age=250, country='Finland', city='Helsinki', gender='male'):
+ self.gender = gender
+ super().__init__(firstname, lastname,age, country, city)
+ def person_info(self):
+ gender = 'He' if self.gender =='male' else 'She'
+ return f'{self.firstname} {self.lastname} is {self.age} years old. {gender} lives in {self.city}, {self.country}.'
+
+s1 = Student('Eyob', 'Yetayeh', 30, 'Finland', 'Helsinki','male')
+s2 = Student('Lidiya', 'Teklemariam', 28, 'Finland', 'Espoo', 'female')
+print(s1.person_info())
+s1.add_skill('JavaScript')
+s1.add_skill('React')
+s1.add_skill('Python')
+print(s1.skills)
+
+print(s2.person_info())
+s2.add_skill('Organizing')
+s2.add_skill('Marketing')
+s2.add_skill('Digital Marketing')
+print(s2.skills)
+```
+
+```sh
+Eyob Yetayeh is 30 years old. He lives in Helsinki, Finland.
+['JavaScript', 'React', 'Python']
+Lidiya Teklemariam is 28 years old. She lives in Espoo, Finland.
+['Organizing', 'Marketing', 'Digital Marketing']
+```
+
+We can use super() built-in function or the parent name Person to automatically inherit the methods and properties from its parent. In the example above we override the parent method. The child method has a different feature, it can identify, if the gender is male or female and assign the proper pronoun(He/She).
+
+🌕 Now, you are fully charged with a super power of programming. Now do some exercises for your brain and muscles.
+
+## 💻 Exercises: Day 21
+
+### Exercises: Level 1
+
+1. Python has the module called _statistics_ and we can use this module to do all the statistical calculations. However, to learn how to make function and reuse function let us try to develop a program, which calculates the measure of central tendency of a sample (mean, median, mode) and measure of variability (range, variance, standard deviation). In addition to those measures, find the min, max, count, percentile, and frequency distribution of the sample. You can create a class called Statistics and create all the functions that do statistical calculations as methods for the Statistics class. Check the output below.
+
+```py
+ages = [31, 26, 34, 37, 27, 26, 32, 32, 26, 27, 27, 24, 32, 33, 27, 25, 26, 38, 37, 31, 34, 24, 33, 29, 26]
+
+print('Count:', data.count()) # 25
+print('Sum: ', data.sum()) # 744
+print('Min: ', data.min()) # 24
+print('Max: ', data.max()) # 38
+print('Range: ', data.range() # 14
+print('Mean: ', data.mean()) # 30
+print('Median: ', data.median()) # 29
+print('Mode: ', data.mode()) # {'mode': 26, 'count': 5}
+print('Standard Deviation: ', data.std()) # 4.2
+print('Variance: ', data.var()) # 17.5
+print('Frequency Distribution: ', data.freq_dist()) # [(20.0, 26), (16.0, 27), (12.0, 32), (8.0, 37), (8.0, 34), (8.0, 33), (8.0, 31), (8.0, 24), (4.0, 38), (4.0, 29), (4.0, 25)]
+```
+
+```sh
+# you output should look like this
+print(data.describe())
+Count: 25
+Sum: 744
+Min: 24
+Max: 38
+Range: 14
+Mean: 30
+Median: 29
+Mode: (26, 5)
+Variance: 17.5
+Standard Deviation: 4.2
+Frequency Distribution: [(20.0, 26), (16.0, 27), (12.0, 32), (8.0, 37), (8.0, 34), (8.0, 33), (8.0, 31), (8.0, 24), (4.0, 38), (4.0, 29), (4.0, 25)]
+```
+
+### Exercises: Level 2
+
+1. Create a class called PersonAccount. It has firstname, lastname, incomes, expenses properties and it has total_income, total_expense, account_info, add_income, add_expense and account_balance methods. Incomes is a set of incomes and its description. The same goes for expenses.
+
+### Exercises: Level 3
+
+
+🎉 CONGRATULATIONS ! 🎉
+
+[<< Day 20](../20_Day_Python_package_manager/20_python_package_manager.md) | [Day 22 >>](../22_Day_Web_scraping/22_web_scraping.md)
diff --git a/21_classes_and_objects/index.html b/21_classes_and_objects/index.html
new file mode 100644
index 0000000..4f7fd77
--- /dev/null
+++ b/21_classes_and_objects/index.html
@@ -0,0 +1,1693 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 21 classes and objects - 30天入门Python全栈开发
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Python is an object oriented programming language. Everything in Python is an object, with its properties and methods. A number, string, list, dictionary, tuple, set etc. used in a program is an object of a corresponding built-in class. We create class to create an object. A class is like an object constructor, or a "blueprint" for creating objects. We instantiate a class to create an object. The class defines attributes and the behavior of the object, while the object, on the other hand, represents the class.
+
We have been working with classes and objects right from the beginning of this challenge unknowingly. Every element in a Python program is an object of a class.
+Let us check if everything in python is a class:
In the examples above, we have created an object from the Person class. However, a class without a constructor is not really useful in real applications. Let us use constructor function to make our class more useful. Like the constructor function in Java or JavaScript, Python has also a built-in init() constructor function. The init constructor function has self parameter which is a reference to the current instance of the class
+Examples:
+
classPerson:
+ def__init__(self,name):
+ # self allows to attach parameter to the class
+ self.name=name
+
+p=Person('Asabeneh')
+print(p.name)
+print(p)
+
Sometimes, you may want to have a default values for your object methods. If we give default values for the parameters in the constructor, we can avoid errors when we call or instantiate our class without parameters. Let's see how it looks:
+
Example:
+
classPerson:
+ def__init__(self,firstname='Asabeneh',lastname='Yetayeh',age=250,country='Finland',city='Helsinki'):
+ self.firstname=firstname
+ self.lastname=lastname
+ self.age=age
+ self.country=country
+ self.city=city
+
+ defperson_info(self):
+ returnf'{self.firstname}{self.lastname} is {self.age} years old. He lives in {self.city}, {self.country}.'
+
+p1=Person()
+print(p1.person_info())
+p2=Person('John','Doe',30,'Nomanland','Noman city')
+print(p2.person_info())
+
In the example below, the person class, all the constructor parameters have default values. In addition to that, we have skills parameter, which we can access using a method. Let us create add_skill method to add skills to the skills list.
Using inheritance we can reuse parent class code. Inheritance allows us to define a class that inherits all the methods and properties from parent class. The parent class or super or base class is the class which gives all the methods and properties. Child class is the class that inherits from another or parent class.
+Let us create a student class by inheriting from person class.
We did not call the init() constructor in the child class. If we didn't call it then we can still access all the properties from the parent. But if we do call the constructor we can access the parent properties by calling super.
+We can add a new method to the child or we can override the parent class methods by creating the same method name in the child class. When we add the init() function, the child class will no longer inherit the parent's init() function.
We can use super() built-in function or the parent name Person to automatically inherit the methods and properties from its parent. In the example above we override the parent method. The child method has a different feature, it can identify, if the gender is male or female and assign the proper pronoun(He/She).
+
🌕 Now, you are fully charged with a super power of programming. Now do some exercises for your brain and muscles.
Python has the module called statistics and we can use this module to do all the statistical calculations. However, to learn how to make function and reuse function let us try to develop a program, which calculates the measure of central tendency of a sample (mean, median, mode) and measure of variability (range, variance, standard deviation). In addition to those measures, find the min, max, count, percentile, and frequency distribution of the sample. You can create a class called Statistics and create all the functions that do statistical calculations as methods for the Statistics class. Check the output below.
# you output should look like this
+print(data.describe())
+Count:25
+Sum:744
+Min:24
+Max:38
+Range:14
+Mean:30
+Median:29
+Mode:(26,5)
+Variance:17.5
+StandardDeviation:4.2
+FrequencyDistribution:[(20.0,26),(16.0,27),(12.0,32),(8.0,37),(8.0,34),(8.0,33),(8.0,31),(8.0,24),(4.0,38),(4.0,29),(4.0,25)]
+
Create a class called PersonAccount. It has firstname, lastname, incomes, expenses properties and it has total_income, total_expense, account_info, add_income, add_expense and account_balance methods. Incomes is a set of incomes and its description. The same goes for expenses.
+
+[<< Day 21](../21_Day_Classes_and_objects/21_classes_and_objects.md) | [Day 23 >>](../23_Day_Virtual_environment/23_virtual_environment.md)
+
+![30DaysOfPython](../images/30DaysOfPython_banner3@2x.png)
+
+- [📘 Day 22](#-day-22)
+ - [Python Web Scraping](#python-web-scraping)
+ - [What is Web Scrapping](#what-is-web-scrapping)
+ - [💻 Exercises: Day 22](#-exercises-day-22)
+
+# 📘 Day 22
+
+## Python Web Scraping
+
+### What is Web Scrapping
+
+The internet is full of huge amount of data which can be used for different purposes. To collect this data we need to know how to scrape data from a website.
+
+Web scraping is the process of extracting and collecting data from websites and storing it on a local machine or in a database.
+
+In this section, we will use beautifulsoup and requests package to scrape data. The package version we are using is beautifulsoup 4.
+
+To start scraping websites you need _requests_, _beautifoulSoup4_ and a _website_.
+
+```sh
+pip install requests
+pip install beautifulsoup4
+```
+
+To scrape data from websites, basic understanding of HTML tags and CSS selectors is needed. We target content from a website using HTML tags, classes or/and ids.
+Let us import the requests and BeautifulSoup module
+
+```py
+import requests
+from bs4 import BeautifulSoup
+```
+
+Let us declare url variable for the website which we are going to scrape.
+
+```py
+
+import requests
+from bs4 import BeautifulSoup
+url = 'https://archive.ics.uci.edu/ml/datasets.php'
+
+# Lets use the requests get method to fetch the data from url
+
+response = requests.get(url)
+# lets check the status
+status = response.status_code
+print(status) # 200 means the fetching was successful
+```
+
+```sh
+200
+```
+
+Using beautifulSoup to parse content from the page
+
+```py
+import requests
+from bs4 import BeautifulSoup
+url = 'https://archive.ics.uci.edu/ml/datasets.php'
+
+response = requests.get(url)
+content = response.content # we get all the content from the website
+soup = BeautifulSoup(content, 'html.parser') # beautiful soup will give a chance to parse
+print(soup.title) # UCI Machine Learning Repository: Data Sets
+print(soup.title.get_text()) # UCI Machine Learning Repository: Data Sets
+print(soup.body) # gives the whole page on the website
+print(response.status_code)
+
+tables = soup.find_all('table', {'cellpadding':'3'})
+# We are targeting the table with cellpadding attribute with the value of 3
+# We can select using id, class or HTML tag , for more information check the beautifulsoup doc
+table = tables[0] # the result is a list, we are taking out data from it
+for td in table.find('tr').find_all('td'):
+ print(td.text)
+```
+
+If you run this code, you can see that the extraction is half done. You can continue doing it because it is part of exercise 1.
+For reference check the [beautifulsoup documentation](https://www.crummy.com/software/BeautifulSoup/bs4/doc/#quick-start)
+
+🌕 You are so special, you are progressing everyday. You are left with only eight days to your way to greatness. Now do some exercises for your brain and muscles.
+
+## 💻 Exercises: Day 22
+
+1. Scrape the following website and store the data as json file(url = 'http://www.bu.edu/president/boston-university-facts-stats/').
+1. Extract the table in this url (https://archive.ics.uci.edu/ml/datasets.php) and change it to a json file
+2. Scrape the presidents table and store the data as json(https://en.wikipedia.org/wiki/List_of_presidents_of_the_United_States). The table is not very structured and the scrapping may take very long time.
+
+🎉 CONGRATULATIONS ! 🎉
+
+[<< Day 21](../21_Day_Web_scraping/21_class_and_object.md) | [Day 23 >>](../23_Day_Virtual_environment/23_virtual_environment.md)
diff --git a/22_web_scraping/index.html b/22_web_scraping/index.html
new file mode 100644
index 0000000..e9483c1
--- /dev/null
+++ b/22_web_scraping/index.html
@@ -0,0 +1,1286 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 22 web scraping - 30天入门Python全栈开发
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
The internet is full of huge amount of data which can be used for different purposes. To collect this data we need to know how to scrape data from a website.
+
Web scraping is the process of extracting and collecting data from websites and storing it on a local machine or in a database.
+
In this section, we will use beautifulsoup and requests package to scrape data. The package version we are using is beautifulsoup 4.
+
To start scraping websites you need requests, beautifoulSoup4 and a website.
+
pipinstallrequests
+pipinstallbeautifulsoup4
+
+
To scrape data from websites, basic understanding of HTML tags and CSS selectors is needed. We target content from a website using HTML tags, classes or/and ids.
+Let us import the requests and BeautifulSoup module
+
importrequests
+frombs4importBeautifulSoup
+
+
Let us declare url variable for the website which we are going to scrape.
+
importrequests
+frombs4importBeautifulSoup
+url='https://archive.ics.uci.edu/ml/datasets.php'
+
+# Lets use the requests get method to fetch the data from url
+
+response=requests.get(url)
+# lets check the status
+status=response.status_code
+print(status)# 200 means the fetching was successful
+
+
200
+
+
Using beautifulSoup to parse content from the page
+
importrequests
+frombs4importBeautifulSoup
+url='https://archive.ics.uci.edu/ml/datasets.php'
+
+response=requests.get(url)
+content=response.content# we get all the content from the website
+soup=BeautifulSoup(content,'html.parser')# beautiful soup will give a chance to parse
+print(soup.title)# <title>UCI Machine Learning Repository: Data Sets</title>
+print(soup.title.get_text())# UCI Machine Learning Repository: Data Sets
+print(soup.body)# gives the whole page on the website
+print(response.status_code)
+
+tables=soup.find_all('table',{'cellpadding':'3'})
+# We are targeting the table with cellpadding attribute with the value of 3
+# We can select using id, class or HTML tag , for more information check the beautifulsoup doc
+table=tables[0]# the result is a list, we are taking out data from it
+fortdintable.find('tr').find_all('td'):
+ print(td.text)
+
+
If you run this code, you can see that the extraction is half done. You can continue doing it because it is part of exercise 1.
+For reference check the beautifulsoup documentation
+
🌕 You are so special, you are progressing everyday. You are left with only eight days to your way to greatness. Now do some exercises for your brain and muscles.
Scrape the following website and store the data as json file(url = 'http://www.bu.edu/president/boston-university-facts-stats/').
+
Extract the table in this url (https://archive.ics.uci.edu/ml/datasets.php) and change it to a json file
+
Scrape the presidents table and store the data as json(https://en.wikipedia.org/wiki/List_of_presidents_of_the_United_States). The table is not very structured and the scrapping may take very long time.
+
+[<< Day 22](../22_Day_Web_scraping/22_web_scraping.md) | [Day 24 >>](../24_Day_Statistics/24_statistics.md)
+
+![30DaysOfPython](../images/30DaysOfPython_banner3@2x.png)
+
+- [📘 Day 23](#-day-23)
+ - [Setting up Virtual Environments](#setting-up-virtual-environments)
+ - [💻 Exercises: Day 23](#-exercises-day-23)
+
+# 📘 Day 23
+
+## Setting up Virtual Environments
+
+To start with project, it would be better to have a virtual environment. Virtual environment can help us to create an isolated or separate environment. This will help us to avoid conflicts in dependencies across projects. If you write pip freeze on your terminal you will see all the installed packages on your computer. If we use virtualenv, we will access only packages which are specific for that project. Open your terminal and install virtualenv
+
+```sh
+asabeneh@Asabeneh:~$ pip install virtualenv
+```
+
+Inside the 30DaysOfPython folder create a flask_project folder.
+
+After installing the virtualenv package go to your project folder and create a virtual env by writing:
+
+For Mac/Linux:
+```sh
+asabeneh@Asabeneh:~/Desktop/30DaysOfPython/flask_project\$ virtualenv venv
+
+```
+
+For Windows:
+```sh
+C:\Users\User\Documents\30DaysOfPython\flask_project>python -m venv venv
+```
+
+I prefer to call the new project venv, but feel free to name it differently. Let us check if the the venv was created by using ls (or dir for windows command prompt) command.
+
+```sh
+asabeneh@Asabeneh:~/Desktop/30DaysOfPython/flask_project$ ls
+venv/
+```
+
+Let us activate the virtual environment by writing the following command at our project folder.
+
+For Mac/Linux:
+```sh
+asabeneh@Asabeneh:~/Desktop/30DaysOfPython/flask_project$ source venv/bin/activate
+```
+Activation of the virtual environment in Windows may very on Windows Power shell and git bash.
+
+For Windows Power Shell:
+```sh
+C:\Users\User\Documents\30DaysOfPython\flask_project> venv\Scripts\activate
+```
+
+For Windows Git bash:
+```sh
+C:\Users\User\Documents\30DaysOfPython\flask_project> venv\Scripts\. activate
+```
+
+After you write the activation command, your project directory will start with venv. See the example below.
+
+```sh
+(venv) asabeneh@Asabeneh:~/Desktop/30DaysOfPython/flask_project$
+```
+
+Now, lets check the available packages in this project by writing pip freeze. You will not see any packages.
+
+We are going to do a small flask project so let us install flask package to this project.
+
+```sh
+(venv) asabeneh@Asabeneh:~/Desktop/30DaysOfPython/flask_project$ pip install Flask
+```
+
+Now, let us write pip freeze to see a list of installed packages in the project:
+
+```sh
+(venv) asabeneh@Asabeneh:~/Desktop/30DaysOfPython/flask_project$ pip freeze
+Click==7.0
+Flask==1.1.1
+itsdangerous==1.1.0
+Jinja2==2.10.3
+MarkupSafe==1.1.1
+Werkzeug==0.16.0
+```
+
+When you finish you should dactivate active project using _deactivate_.
+
+```sh
+(venv) asabeneh@Asabeneh:~/Desktop/30DaysOfPython$ deactivate
+```
+
+The necessary modules to work with flask are installed. Now, your project directory is ready for a flask project. You should include the venv to your .gitignore file not to push it to github.
+
+## 💻 Exercises: Day 23
+
+1. Create a project directory with a virtual environment based on the example given above.
+
+🎉 CONGRATULATIONS ! 🎉
+
+[<< Day 22](../22_Day_Web_scraping/22_web_scraping.md) | [Day 24 >>](../24_Day_Statistics/24_statistics.md)
diff --git a/23_virtual_environment/index.html b/23_virtual_environment/index.html
new file mode 100644
index 0000000..12fe7fe
--- /dev/null
+++ b/23_virtual_environment/index.html
@@ -0,0 +1,1247 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 23 virtual environment - 30天入门Python全栈开发
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
To start with project, it would be better to have a virtual environment. Virtual environment can help us to create an isolated or separate environment. This will help us to avoid conflicts in dependencies across projects. If you write pip freeze on your terminal you will see all the installed packages on your computer. If we use virtualenv, we will access only packages which are specific for that project. Open your terminal and install virtualenv
+
asabeneh@Asabeneh:~$pipinstallvirtualenv
+
+
Inside the 30DaysOfPython folder create a flask_project folder.
+
After installing the virtualenv package go to your project folder and create a virtual env by writing:
I prefer to call the new project venv, but feel free to name it differently. Let us check if the the venv was created by using ls (or dir for windows command prompt) command.
The necessary modules to work with flask are installed. Now, your project directory is ready for a flask project. You should include the venv to your .gitignore file not to push it to github.
Statistics is the discipline that studies the collection, organization, displaying, analysing, interpretation and presentation of data.
+Statistics is a branch of Mathematics that is recommended to be a prerequisite for data science and machine learning. Statistics is a very broad field but we will focus in this section only on the most relevant part.
+After completing this challenge, you may go onto the web development, data analysis, machine learning and data science path. Whatever path you may follow, at some point in your career you will get data which you may work on. Having some statistical knowledge will help you to make decisions based on data, data tells as they say.
What is data? Data is any set of characters that is gathered and translated for some purpose, usually analysis. It can be any character, including text and numbers, pictures, sound, or video. If data is not put in a context, it doesn't make any sense to a human or computer. To make sense from data we need to work on the data using different tools.
+
The work flow of data analysis, data science or machine learning starts from data. Data can be provided from some data source or it can be created. There are structured and unstructured data.
+
Data can be found in small or big format. Most of the data types we will get have been covered in the file handling section.
The Python statistics module provides functions for calculating mathematical statistics of numerical data. The module is not intended to be a competitor to third-party libraries such as NumPy, SciPy, or proprietary full-featured statistics packages aimed at professional statisticians such as Minitab, SAS and Matlab. It is aimed at the level of graphing and scientific calculators.
In the first section we defined Python as a great general-purpose programming language on its own, but with the help of other popular libraries as(numpy, scipy, matplotlib, pandas etc) it becomes a powerful environment for scientific computing.
+
NumPy is the core library for scientific computing in Python. It provides a high-performance multidimensional array object, and tools for working with arrays.
+
So far, we have been using vscode but from now on I would recommend using Jupyter Notebook. To access jupyter notebook let's install anaconda. If you are using anaconda most of the common packages are included and you don't have install packages if you installed anaconda.
Jupyter notebook is available if your are in favor of jupyter notebook
+
# How to import numpy
+ importnumpyasnp
+ # How to check the version of the numpy package
+ print('numpy:',np.__version__)
+ # Checking the available methods
+ print(dir(np))
+
# We can always convert an array back to a python list using tolist().
+np_to_list=numpy_array_from_list.tolist()
+print(type(np_to_list))
+print('one dimensional array:',np_to_list)
+print('two dimensional array: ',numpy_two_dimensional_list.tolist())
+
The shape method provide the shape of the array as a tuple. The first is the row and the second is the column. If the array is just one dimensional it returns the size of the array.
NumPy array is not like exactly like python list. To do mathematical operation in Python list we have to loop through the items but numpy can allow to do any mathematical operation without looping.
+Mathematical Operation:
# Floor division: the division result without the remainder
+numpy_array_from_list=np.array([1,2,3,4,5])
+print('original array: ',numpy_array_from_list)
+ten_times_original=numpy_array_from_list//10
+print(ten_times_original)
+
# Exponential is finding some number the power of another:
+numpy_array_from_list=np.array([1,2,3,4,5])
+print('original array: ',numpy_array_from_list)
+ten_times_original=numpy_array_from_list**2
+print(ten_times_original)
+
Sometimes, you want to create values that are evenly spaced within a defined interval. For instance, you want to create values from 1 to 10; you can use numpy.arange() function
+
# creating list using range(starting, stop, step)
+lst=range(0,11,2)
+lst
+
+
range(0,11,2)
+
+
forlinlst:
+ print(l)
+
+
```sh 0
+ 2
+ 4
+ 6
+ 8
+ 10
+
```py
+# Similar to range arange numpy.arange(start, stop, step)
+whole_numbers = np.arange(0, 20, 1)
+whole_numbers
+
# numpy.linspace()
+# numpy.logspace() in Python with Example
+# For instance, it can be used to create 10 values from 1 to 5 evenly spaced.
+np.linspace(1.0,5.0,num=10)
+
# not to include the last value in the interval
+np.linspace(1.0,5.0,num=5,endpoint=False)
+
+
array([1. , 1.8, 2.6, 3.4, 4.2])
+
+
# LogSpace
+# LogSpace returns even spaced numbers on a log scale. Logspace has the same parameters as np.linspace.
+
+# Syntax:
+
+# numpy.logspace(start, stop, num, endpoint)
+
+np.logspace(2,4.0,num=4)
+
+
array([100.,464.15888336,2154.43469003,10000.])
+
+
# to check the size of an array
+x=np.array([1,2,3],dtype=np.complex128)
+
+
x
+
+
array([1.+0.j,2.+0.j,3.+0.j])
+
+
x.itemsize
+
+
16
+
+
# indexing and Slicing NumPy Arrays in Python
+np_list=np.array([(1,2,3),(4,5,6)])
+np_list
+
NumPy has quite useful statistical functions for finding minimum, maximum, mean, median, percentile,standard deviation and variance, etc from the given elements in the array.
+The functions are explained as follows −
+Statistical function
+Numpy is equipped with the robust statistical function as listed below
a=[1,2,3]
+
+# Repeat whole of 'a' two times
+print('Tile: ',np.tile(a,2))
+
+# Repeat each element of 'a' two times
+print('Repeat: ',np.repeat(a,2))
+
# numpy.dot(): Dot Product in Python using Numpy
+# Dot Product
+# Numpy is powerful library for matrices computation. For instance, you can compute the dot product with np.dot
+
+# Syntax
+
+# numpy.dot(x, y, out=None)
+
plt.plot(temp,pressure)
+plt.xlabel('Temperature in oC')
+plt.ylabel('Pressure in atm')
+plt.title('Temperature vs Pressure')
+plt.xticks(np.arange(0,6,step=0.5))
+plt.show()
+
+
+
To draw the Gaussian normal distribution using numpy. As you can see below, the numpy can generate random numbers. To create random sample, we need the mean(mu), sigma(standard deviation), mumber of data points.
+
+[<< Day 24](../24_Day_Statistics/24_statistics.md) | [Day 26 >>](../26_Day_Python_web/26_python_web.md)
+
+![30DaysOfPython](../images/30DaysOfPython_banner3@2x.png)
+
+- [📘 Day 25](#-day-25)
+ - [Pandas](#pandas)
+ - [Installing Pandas](#installing-pandas)
+ - [Importing Pandas](#importing-pandas)
+ - [Creating Pandas Series with Default Index](#creating-pandas-series-with-default-index)
+ - [Creating Pandas Series with custom index](#creating--pandas-series-with-custom-index)
+ - [Creating Pandas Series from a Dictionary](#creating-pandas-series-from-a-dictionary)
+ - [Creating a Constant Pandas Series](#creating-a-constant-pandas-series)
+ - [Creating a Pandas Series Using Linspace](#creating-a--pandas-series-using-linspace)
+ - [DataFrames](#dataframes)
+ - [Creating DataFrames from List of Lists](#creating-dataframes-from-list-of-lists)
+ - [Creating DataFrame Using Dictionary](#creating-dataframe-using-dictionary)
+ - [Creating DataFrames from a List of Dictionaries](#creating-dataframes-from-a-list-of-dictionaries)
+ - [Reading CSV File Using Pandas](#reading-csv-file-using-pandas)
+ - [Data Exploration](#data-exploration)
+ - [Modifying a DataFrame](#modifying-a-dataframe)
+ - [Creating a DataFrame](#creating-a-dataframe)
+ - [Adding a New Column](#adding-a-new-column)
+ - [Modifying column values](#modifying-column-values)
+ - [Formating DataFrame columns](#formating-dataframe-columns)
+ - [Checking data types of Column values](#checking-data-types-of-column-values)
+ - [Boolean Indexing](#boolean-indexing)
+ - [Exercises: Day 25](#exercises-day-25)
+
+# 📘 Day 25
+
+## Pandas
+
+Pandas is an open source, high-performance, easy-to-use data structures and data analysis tools for the Python programming language.
+Pandas adds data structures and tools designed to work with table-like data which is *Series* and *Data Frames*.
+Pandas provides tools for data manipulation:
+
+- reshaping
+- merging
+- sorting
+- slicing
+- aggregation
+- imputation.
+If you are using anaconda, you do not have install pandas.
+
+### Installing Pandas
+
+For Mac:
+```py
+pip install conda
+conda install pandas
+```
+
+For Windows:
+```py
+pip install conda
+pip install pandas
+```
+
+Pandas data structure is based on *Series* and *DataFrames*.
+
+A *series* is a *column* and a DataFrame is a *multidimensional table* made up of collection of *series*. In order to create a pandas series we should use numpy to create a one dimensional arrays or a python list.
+Let us see an example of a series:
+
+Names Pandas Series
+
+![pandas series](../images/pandas-series-1.png)
+
+Countries Series
+
+![pandas series](../images/pandas-series-2.png)
+
+Cities Series
+
+![pandas series](../images/pandas-series-3.png)
+
+As you can see, pandas series is just one column of data. If we want to have multiple columns we use data frames. The example below shows pandas DataFrames.
+
+Let us see, an example of a pandas data frame:
+
+![Pandas data frame](../images/pandas-dataframe-1.png)
+
+Data frame is a collection of rows and columns. Look at the table below; it has many more columns than the example above:
+
+![Pandas data frame](../images/pandas-dataframe-2.png)
+
+Next, we will see how to import pandas and how to create Series and DataFrames using pandas
+
+### Importing Pandas
+
+```python
+import pandas as pd # importing pandas as pd
+import numpy as np # importing numpy as np
+```
+
+### Creating Pandas Series with Default Index
+
+```python
+nums = [1, 2, 3, 4,5]
+s = pd.Series(nums)
+print(s)
+```
+
+```sh
+ 0 1
+ 1 2
+ 2 3
+ 3 4
+ 4 5
+ dtype: int64
+```
+
+### Creating Pandas Series with custom index
+
+```python
+nums = [1, 2, 3, 4, 5]
+s = pd.Series(nums, index=[1, 2, 3, 4, 5])
+print(s)
+```
+
+```sh
+ 1 1
+ 2 2
+ 3 3
+ 4 4
+ 5 5
+ dtype: int64
+```
+
+```python
+fruits = ['Orange','Banana','Mango']
+fruits = pd.Series(fruits, index=[1, 2, 3])
+print(fruits)
+```
+
+```sh
+ 1 Orange
+ 2 Banana
+ 3 Mango
+ dtype: object
+```
+
+### Creating Pandas Series from a Dictionary
+
+```python
+dct = {'name':'Asabeneh','country':'Finland','city':'Helsinki'}
+```
+
+```python
+s = pd.Series(dct)
+print(s)
+```
+
+```sh
+ name Asabeneh
+ country Finland
+ city Helsinki
+ dtype: object
+```
+
+### Creating a Constant Pandas Series
+
+```python
+s = pd.Series(10, index = [1, 2, 3])
+print(s)
+```
+
+```sh
+ 1 10
+ 2 10
+ 3 10
+ dtype: int64
+```
+
+### Creating a Pandas Series Using Linspace
+
+```python
+s = pd.Series(np.linspace(5, 20, 10)) # linspace(starting, end, items)
+print(s)
+```
+
+```sh
+ 0 5.000000
+ 1 6.666667
+ 2 8.333333
+ 3 10.000000
+ 4 11.666667
+ 5 13.333333
+ 6 15.000000
+ 7 16.666667
+ 8 18.333333
+ 9 20.000000
+ dtype: float64
+```
+
+## DataFrames
+
+Pandas data frames can be created in different ways.
+
+### Creating DataFrames from List of Lists
+
+```python
+data = [
+ ['Asabeneh', 'Finland', 'Helsink'],
+ ['David', 'UK', 'London'],
+ ['John', 'Sweden', 'Stockholm']
+]
+df = pd.DataFrame(data, columns=['Names','Country','City'])
+print(df)
+```
+
+
+
+## Reading CSV File Using Pandas
+
+To download the CSV file, what is needed in this example, console/command line is enough:
+
+```sh
+curl -O https://raw.githubusercontent.com/Asabeneh/30-Days-Of-Python/master/data/weight-height.csv
+```
+
+Put the downloaded file in your working directory.
+
+```python
+import pandas as pd
+
+df = pd.read_csv('weight-height.csv')
+print(df)
+```
+
+### Data Exploration
+
+Let us read only the first 5 rows using head()
+
+```python
+print(df.head()) # give five rows we can increase the number of rows by passing argument to the head() method
+```
+
+
+
+
+
+
+
Gender
+
Height
+
Weight
+
+
+
+
+
0
+
Male
+
73.847017
+
241.893563
+
+
+
1
+
Male
+
68.781904
+
162.310473
+
+
+
2
+
Male
+
74.110105
+
212.740856
+
+
+
3
+
Male
+
71.730978
+
220.042470
+
+
+
4
+
Male
+
69.881796
+
206.349801
+
+
+
+
+Let us also explore the last recordings of the dataframe using the tail() methods.
+
+```python
+print(df.tail()) # tails give the last five rows, we can increase the rows by passing argument to tail method
+```
+
+
+
+
+
+
Gender
+
Height
+
Weight
+
+
+
+
+
9995
+
Female
+
66.172652
+
136.777454
+
+
+
9996
+
Female
+
67.067155
+
170.867906
+
+
+
9997
+
Female
+
63.867992
+
128.475319
+
+
+
9998
+
Female
+
69.034243
+
163.852461
+
+
+
9999
+
Female
+
61.944246
+
113.649103
+
+
+
+
+As you can see the csv file has three rows: Gender, Height and Weight. If the DataFrame would have a long rows, it would be hard to know all the columns. Therefore, we should use a method to know the colums. we do not know the number of rows. Let's use shape meathod.
+
+```python
+print(df.shape) # as you can see 10000 rows and three columns
+```
+
+ (10000, 3)
+
+Let us get all the columns using columns.
+
+```python
+print(df.columns)
+```
+
+ Index(['Gender', 'Height', 'Weight'], dtype='object')
+
+Now, let us get a specific column using the column key
+
+```python
+heights = df['Height'] # this is now a series
+```
+
+```python
+print(heights)
+```
+
+```sh
+ 0 73.847017
+ 1 68.781904
+ 2 74.110105
+ 3 71.730978
+ 4 69.881796
+ ...
+ 9995 66.172652
+ 9996 67.067155
+ 9997 63.867992
+ 9998 69.034243
+ 9999 61.944246
+ Name: Height, Length: 10000, dtype: float64
+```
+
+```python
+weights = df['Weight'] # this is now a series
+```
+
+```python
+print(weights)
+```
+
+```sh
+ 0 241.893563
+ 1 162.310473
+ 2 212.740856
+ 3 220.042470
+ 4 206.349801
+ ...
+ 9995 136.777454
+ 9996 170.867906
+ 9997 128.475319
+ 9998 163.852461
+ 9999 113.649103
+ Name: Weight, Length: 10000, dtype: float64
+```
+
+```python
+print(len(heights) == len(weights))
+```
+
+ True
+
+The describe() method provides a descriptive statistical values of a dataset.
+
+```python
+print(heights.describe()) # give statisical information about height data
+```
+
+```sh
+ count 10000.000000
+ mean 66.367560
+ std 3.847528
+ min 54.263133
+ 25% 63.505620
+ 50% 66.318070
+ 75% 69.174262
+ max 78.998742
+ Name: Height, dtype: float64
+```
+
+```python
+print(weights.describe())
+```
+
+```sh
+ count 10000.000000
+ mean 161.440357
+ std 32.108439
+ min 64.700127
+ 25% 135.818051
+ 50% 161.212928
+ 75% 187.169525
+ max 269.989699
+ Name: Weight, dtype: float64
+```
+
+```python
+print(df.describe()) # describe can also give statistical information from a dataFrame
+```
+
+
+
+
+
+
Height
+
Weight
+
+
+
+
+
count
+
10000.000000
+
10000.000000
+
+
+
mean
+
66.367560
+
161.440357
+
+
+
std
+
3.847528
+
32.108439
+
+
+
min
+
54.263133
+
64.700127
+
+
+
25%
+
63.505620
+
135.818051
+
+
+
50%
+
66.318070
+
161.212928
+
+
+
75%
+
69.174262
+
187.169525
+
+
+
max
+
78.998742
+
269.989699
+
+
+
+
+Similar to describe(), the info() method also give information about the dataset.
+
+## Modifying a DataFrame
+
+Modifying a DataFrame:
+ * We can create a new DataFrame
+ * We can create a new column and add it to the DataFrame,
+ * we can remove an existing column from a DataFrame,
+ * we can modify an existing column in a DataFrame,
+ * we can change the data type of column values in the DataFrame
+
+### Creating a DataFrame
+
+As always, first we import the necessary packages. Now, lets import pandas and numpy, two best friends ever.
+
+```python
+import pandas as pd
+import numpy as np
+data = [
+ {"Name": "Asabeneh", "Country":"Finland","City":"Helsinki"},
+ {"Name": "David", "Country":"UK","City":"London"},
+ {"Name": "John", "Country":"Sweden","City":"Stockholm"}]
+df = pd.DataFrame(data)
+print(df)
+```
+
+
+
+
+
+
Name
+
Country
+
City
+
+
+
+
+
0
+
Asabeneh
+
Finland
+
Helsinki
+
+
+
1
+
David
+
UK
+
London
+
+
+
2
+
John
+
Sweden
+
Stockholm
+
+
+
+
+Adding a column to a DataFrame is like adding a key to a dictionary.
+
+First let's use the previous example to create a DataFrame. After we create the DataFrame, we will start modifying the columns and column values.
+
+### Adding a New Column
+
+Let's add a weight column in the DataFrame
+
+```python
+weights = [74, 78, 69]
+df['Weight'] = weights
+df
+```
+
+
+
+
+
+
Name
+
Country
+
City
+
Weight
+
+
+
+
+
0
+
Asabeneh
+
Finland
+
Helsinki
+
74
+
+
+
1
+
David
+
UK
+
London
+
78
+
+
+
2
+
John
+
Sweden
+
Stockholm
+
69
+
+
+
+
+Let's add a height column into the DataFrame aswell
+
+```python
+heights = [173, 175, 169]
+df['Height'] = heights
+print(df)
+```
+
+
+
+
+
+
Name
+
Country
+
City
+
Weight
+
Height
+
+
+
+
+
0
+
Asabeneh
+
Finland
+
Helsinki
+
74
+
173
+
+
+
1
+
David
+
UK
+
London
+
78
+
175
+
+
+
2
+
John
+
Sweden
+
Stockholm
+
69
+
169
+
+
+
+
+As you can see in the DataFrame above, we did add new columns, Weight and Height. Let's add one additional column called BMI(Body Mass Index) by calculating their BMI using thier mass and height. BMI is mass divided by height squared (in meters) - Weight/Height * Height.
+
+As you can see, the height is in centimeters, so we shoud change it to meters. Let's modify the height row.
+
+### Modifying column values
+
+```python
+df['Height'] = df['Height'] * 0.01
+df
+```
+
+
+
+
+
+
Name
+
Country
+
City
+
Weight
+
Height
+
+
+
+
+
0
+
Asabeneh
+
Finland
+
Helsinki
+
74
+
1.73
+
+
+
1
+
David
+
UK
+
London
+
78
+
1.75
+
+
+
2
+
John
+
Sweden
+
Stockholm
+
69
+
1.69
+
+
+
+
+```python
+# Using functions makes our code clean, but you can calculate the bmi without one
+def calculate_bmi ():
+ weights = df['Weight']
+ heights = df['Height']
+ bmi = []
+ for w,h in zip(weights, heights):
+ b = w/(h*h)
+ bmi.append(b)
+ return bmi
+
+bmi = calculate_bmi()
+
+```
+
+
+```python
+df['BMI'] = bmi
+df
+```
+
+
+
+
+
+
Name
+
Country
+
City
+
Weight
+
Height
+
BMI
+
+
+
+
+
0
+
Asabeneh
+
Finland
+
Helsinki
+
74
+
1.73
+
24.725183
+
+
+
1
+
David
+
UK
+
London
+
78
+
1.75
+
25.469388
+
+
+
2
+
John
+
Sweden
+
Stockholm
+
69
+
1.69
+
24.158818
+
+
+
+
+### Formating DataFrame columns
+
+The BMI column values of the DataFrame are float with many significant digits after decimal. Let's change it to one significant digit after point.
+
+```python
+df['BMI'] = round(df['BMI'], 1)
+print(df)
+```
+
+
+
+
+
+
Name
+
Country
+
City
+
Weight
+
Height
+
BMI
+
+
+
+
+
0
+
Asabeneh
+
Finland
+
Helsinki
+
74
+
1.73
+
24.7
+
+
+
1
+
David
+
UK
+
London
+
78
+
1.75
+
25.5
+
+
+
2
+
John
+
Sweden
+
Stockholm
+
69
+
1.69
+
24.2
+
+
+
+
+The information in the DataFrame seems not yet complete, let's add birth year and current year columns.
+
+```python
+birth_year = ['1769', '1985', '1990']
+current_year = pd.Series(2020, index=[0, 1,2])
+df['Birth Year'] = birth_year
+df['Current Year'] = current_year
+df
+```
+
+
+
+
+
+
Name
+
Country
+
City
+
Weight
+
Height
+
BMI
+
Birth Year
+
Current Year
+
+
+
+
+
0
+
Asabeneh
+
Finland
+
Helsinki
+
74
+
1.73
+
24.7
+
1769
+
2020
+
+
+
1
+
David
+
UK
+
London
+
78
+
1.75
+
25.5
+
1985
+
2020
+
+
+
2
+
John
+
Sweden
+
Stockholm
+
69
+
1.69
+
24.2
+
1990
+
2020
+
+
+
+
+## Checking data types of Column values
+
+```python
+print(df.Weight.dtype)
+```
+
+```sh
+ dtype('int64')
+```
+
+```python
+df['Birth Year'].dtype # it gives string object , we should change this to number
+
+```
+
+```python
+df['Birth Year'] = df['Birth Year'].astype('int')
+print(df['Birth Year'].dtype) # let's check the data type now
+```
+
+```sh
+ dtype('int32')
+```
+
+Now same for the current year:
+
+```python
+df['Current Year'] = df['Current Year'].astype('int')
+df['Current Year'].dtype
+```
+
+```sh
+ dtype('int32')
+```
+
+Now, the column values of birth year and current year are integers. We can calculate the age.
+
+```python
+ages = df['Current Year'] - df['Birth Year']
+ages
+```
+
+ 0 251
+ 1 35
+ 2 30
+ dtype: int32
+
+```python
+df['Ages'] = ages
+print(df)
+```
+
+
+
+
+
+
Name
+
Country
+
City
+
Weight
+
Height
+
BMI
+
Birth Year
+
Current Year
+
Ages
+
+
+
+
+
0
+
Asabeneh
+
Finland
+
Helsinki
+
74
+
1.73
+
24.7
+
1769
+
2019
+
250
+
+
+
1
+
David
+
UK
+
London
+
78
+
1.75
+
25.5
+
1985
+
2019
+
34
+
+
+
2
+
John
+
Sweden
+
Stockholm
+
69
+
1.69
+
24.2
+
1990
+
2019
+
29
+
+
+
+
+The person in the first row lived so far for 251 years. It is unlikely for someone to live so long. Either it is a typo or the data is cooked. So lets fill that data with average of the columns without including outlier.
+
+mean = (35 + 30)/ 2
+
+```python
+mean = (35 + 30)/ 2
+print('Mean: ',mean) #it is good to add some description to the output, so we know what is what
+```
+
+```sh
+ Mean: 32.5
+```
+
+### Boolean Indexing
+
+```python
+print(df[df['Ages'] > 120])
+```
+
+
Pandas is an open source, high-performance, easy-to-use data structures and data analysis tools for the Python programming language.
+Pandas adds data structures and tools designed to work with table-like data which is Series and Data Frames.
+Pandas provides tools for data manipulation:
+
+
reshaping
+
merging
+
sorting
+
slicing
+
aggregation
+
imputation.
+If you are using anaconda, you do not have install pandas.
Pandas data structure is based on Series and DataFrames.
+
A series is a column and a DataFrame is a multidimensional table made up of collection of series. In order to create a pandas series we should use numpy to create a one dimensional arrays or a python list.
+Let us see an example of a series:
+
Names Pandas Series
+
+
Countries Series
+
+
Cities Series
+
+
As you can see, pandas series is just one column of data. If we want to have multiple columns we use data frames. The example below shows pandas DataFrames.
+
Let us see, an example of a pandas data frame:
+
+
Data frame is a collection of rows and columns. Look at the table below; it has many more columns than the example above:
+
+
Next, we will see how to import pandas and how to create Series and DataFrames using pandas
print(df.head())# give five rows we can increase the number of rows by passing argument to the head() method
+
+
+
+
+
+
Gender
+
Height
+
Weight
+
+
+
+
+
0
+
Male
+
73.847017
+
241.893563
+
+
+
1
+
Male
+
68.781904
+
162.310473
+
+
+
2
+
Male
+
74.110105
+
212.740856
+
+
+
3
+
Male
+
71.730978
+
220.042470
+
+
+
4
+
Male
+
69.881796
+
206.349801
+
+
+
+
+
Let us also explore the last recordings of the dataframe using the tail() methods.
+
print(df.tail())# tails give the last five rows, we can increase the rows by passing argument to tail method
+
+
+
+
+
+
Gender
+
Height
+
Weight
+
+
+
+
+
9995
+
Female
+
66.172652
+
136.777454
+
+
+
9996
+
Female
+
67.067155
+
170.867906
+
+
+
9997
+
Female
+
63.867992
+
128.475319
+
+
+
9998
+
Female
+
69.034243
+
163.852461
+
+
+
9999
+
Female
+
61.944246
+
113.649103
+
+
+
+
+
As you can see the csv file has three rows: Gender, Height and Weight. If the DataFrame would have a long rows, it would be hard to know all the columns. Therefore, we should use a method to know the colums. we do not know the number of rows. Let's use shape meathod.
+
print(df.shape)# as you can see 10000 rows and three columns
+
Modifying a DataFrame:
+ * We can create a new DataFrame
+ * We can create a new column and add it to the DataFrame,
+ * we can remove an existing column from a DataFrame,
+ * we can modify an existing column in a DataFrame,
+ * we can change the data type of column values in the DataFrame
As you can see in the DataFrame above, we did add new columns, Weight and Height. Let's add one additional column called BMI(Body Mass Index) by calculating their BMI using thier mass and height. BMI is mass divided by height squared (in meters) - Weight/Height * Height.
+
As you can see, the height is in centimeters, so we shoud change it to meters. Let's modify the height row.
# Using functions makes our code clean, but you can calculate the bmi without one
+defcalculate_bmi():
+ weights=df['Weight']
+ heights=df['Height']
+ bmi=[]
+ forw,hinzip(weights,heights):
+ b=w/(h*h)
+ bmi.append(b)
+ returnbmi
+
+bmi=calculate_bmi()
+
Now, the column values of birth year and current year are integers. We can calculate the age.
+
ages=df['Current Year']-df['Birth Year']
+ages
+
+
0 251
+1 35
+2 30
+dtype: int32
+
+
df['Ages']=ages
+print(df)
+
+
+
+
+
+
Name
+
Country
+
City
+
Weight
+
Height
+
BMI
+
Birth Year
+
Current Year
+
Ages
+
+
+
+
+
0
+
Asabeneh
+
Finland
+
Helsinki
+
74
+
1.73
+
24.7
+
1769
+
2019
+
250
+
+
+
1
+
David
+
UK
+
London
+
78
+
1.75
+
25.5
+
1985
+
2019
+
34
+
+
+
2
+
John
+
Sweden
+
Stockholm
+
69
+
1.69
+
24.2
+
1990
+
2019
+
29
+
+
+
+
+
The person in the first row lived so far for 251 years. It is unlikely for someone to live so long. Either it is a typo or the data is cooked. So lets fill that data with average of the columns without including outlier.
+
mean = (35 + 30)/ 2
+
mean=(35+30)/2
+print('Mean: ',mean)#it is good to add some description to the output, so we know what is what
+
+
+
+[<< Day 25 ](../25_Day_Pandas/25_pandas.md) | [Day 27 >>](../27_Day_Python_with_mongodb/27_python_with_mongodb.md)
+
+![30DaysOfPython](../images/30DaysOfPython_banner3@2x.png)
+
+- [📘 Day 26](#-day-26)
+ - [Python for Web](#python-for-web)
+ - [Flask](#flask)
+ - [Folder structure](#folder-structure)
+ - [Setting up your project directory](#setting-up-your-project-directory)
+ - [Creating routes](#creating-routes)
+ - [Creating templates](#creating-templates)
+ - [Python Script](#python-script)
+ - [Navigation](#navigation)
+ - [Creating a layout](#creating-a-layout)
+ - [Serving Static File](#serving-static-file)
+ - [Deployment](#deployment)
+ - [Creating Heroku account](#creating-heroku-account)
+ - [Login to Heroku](#login-to-heroku)
+ - [Create requirements and Procfile](#create-requirements-and-procfile)
+ - [Pushing project to heroku](#pushing-project-to-heroku)
+ - [Exercises: Day 26](#exercises-day-26)
+
+# 📘 Day 26
+
+## Python for Web
+
+Python is a general purpose programming language and it can be used for many places. In this section, we will see how we use Python for the web. There are many Python web frame works. Django and Flask are the most popular ones. Today, we will see how to use Flask for web development.
+
+### Flask
+
+Flask is a web development framework written in Python. Flask uses Jinja2 template engine. Flask can be also used with other modern front libraries such as React.
+
+If you did not install the virtualenv package yet install it first. Virtual environment will allows to isolate project dependencies from the local machine dependencies.
+
+#### Folder structure
+
+After completing all the step, your project file structure should look like this:
+
+```sh
+
+├── Procfile
+├── app.py
+├── env
+│ ├── bin
+├── requirements.txt
+├── static
+│ └── css
+│ └── main.css
+└── templates
+ ├── about.html
+ ├── home.html
+ ├── layout.html
+ ├── post.html
+ └── result.html
+```
+
+### Setting up your project directory
+
+Follow the following steps to get started with Flask.
+
+Step 1: install virtualenv using the following command.
+
+```sh
+pip install virtualenv
+```
+
+Step 2:
+
+```sh
+asabeneh@Asabeneh:~/Desktop$ mkdir python_for_web
+asabeneh@Asabeneh:~/Desktop$ cd python_for_web/
+asabeneh@Asabeneh:~/Desktop/python_for_web$ virtualenv venv
+asabeneh@Asabeneh:~/Desktop/python_for_web$ source venv/bin/activate
+(env) asabeneh@Asabeneh:~/Desktop/python_for_web$ pip freeze
+(env) asabeneh@Asabeneh:~/Desktop/python_for_web$ pip install Flask
+(env) asabeneh@Asabeneh:~/Desktop/python_for_web$ pip freeze
+Click==7.0
+Flask==1.1.1
+itsdangerous==1.1.0
+Jinja2==2.10.3
+MarkupSafe==1.1.1
+Werkzeug==0.16.0
+(env) asabeneh@Asabeneh:~/Desktop/python_for_web$
+```
+
+We created a project director named python_for_web. Inside the project we created a virtual environment *venv* which could be any name but I prefer to call it _venv_. Then we activated the virtual environment. We used pip freeze to check the installed packages in the project directory. The result of pip freeze was empty because a package was not installed yet.
+
+Now, let's create app.py file in the project directory and write the following code. The app.py file will be the main file in the project. The following code has flask module, os module.
+
+### Creating routes
+
+The home route.
+
+```py
+# let's import the flask
+from flask import Flask
+import os # importing operating system module
+
+app = Flask(__name__)
+
+@app.route('/') # this decorator create the home route
+def home ():
+ return '
'
+
+
+if __name__ == '__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port = int(os.environ.get("PORT", 5000))
+ app.run(debug=True, host='0.0.0.0', port=port)
+```
+
+To run the flask application, write python app.py in the main flask application directory.
+
+After you run _python app.py_ check local host 5000.
+
+Let us add additional route.
+Creating about route
+
+```py
+# let's import the flask
+from flask import Flask
+import os # importing operating system module
+
+app = Flask(__name__)
+
+@app.route('/') # this decorator create the home route
+def home ():
+ return '
'
+
+if __name__ == '__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port = int(os.environ.get("PORT", 5000))
+ app.run(debug=True, host='0.0.0.0', port=port)
+```
+
+Now, we added the about route in the above code. How about if we want to render an HTML file instead of string? It is possible to render HTML file using the function *render_templae*. Let us create a folder called templates and create home.html and about.html in the project directory. Let us also import the *render_template* function from flask.
+
+### Creating templates
+
+Create the HTML files inside templates folder.
+
+home.html
+
+```html
+
+
+
+
+
+ Home
+
+
+
+
+
+
+```
+
+### Python Script
+
+app.py
+
+```py
+# let's import the flask
+from flask import Flask, render_template
+import os # importing operating system module
+
+app = Flask(__name__)
+
+@app.route('/') # this decorator create the home route
+def home ():
+ return render_template('home.html')
+
+@app.route('/about')
+def about():
+ return render_template('about.html')
+
+if __name__ == '__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port = int(os.environ.get("PORT", 5000))
+ app.run(debug=True, host='0.0.0.0', port=port)
+```
+
+As you can see to go to different pages or to navigate we need a navigation. Let's add a link to each page or let's create a layout which we use to every page.
+
+### Navigation
+
+```html
+
+```
+
+Now, we can navigate between the pages using the above link. Let us create additional page which handle form data. You can call it any name, I like to call it post.html.
+
+We can inject data to the HTML files using Jinja2 template engine.
+
+```py
+# let's import the flask
+from flask import Flask, render_template, request, redirect, url_for
+import os # importing operating system module
+
+app = Flask(__name__)
+
+@app.route('/') # this decorator create the home route
+def home ():
+ techs = ['HTML', 'CSS', 'Flask', 'Python']
+ name = '30 Days Of Python Programming'
+ return render_template('home.html', techs=techs, name = name, title = 'Home')
+
+@app.route('/about')
+def about():
+ name = '30 Days Of Python Programming'
+ return render_template('about.html', name = name, title = 'About Us')
+
+@app.route('/post')
+def post():
+ name = 'Text Analyzer'
+ return render_template('post.html', name = name, title = name)
+
+
+if __name__ == '__main__':
+ # for deployment
+ # to make it work for both production and development
+ port = int(os.environ.get("PORT", 5000))
+ app.run(debug=True, host='0.0.0.0', port=port)
+```
+
+Let's see the templates too:
+
+home.html
+
+```html
+
+
+
+
+
+ Home
+
+
+
+
+
+
+```
+
+### Creating a layout
+
+In the template files, there are lots of repeated codes, we can write a layout and we can remove the repetition. Let's create layout.html inside the templates folder.
+After we create the layout we will import to every file.
+
+#### Serving Static File
+
+Create a static folder in your project directory. Inside the static folder create CSS or styles folder and create a CSS stylesheet. We use the *url_for* module to serve the static file.
+
+layout.html
+
+```html
+
+
+
+
+
+
+
+ {% if title %}
+ 30 Days of Python - {{ title}}
+ {% else %}
+ 30 Days of Python
+ {% endif %}
+
+
+
+
+
+
+
+ {% block content %} {% endblock %}
+
+
+
+```
+
+Now, lets remove all the repeated code in the other template files and import the layout.html. The href is using _url_for_ function with the name of the route function to connect each navigation route.
+
+home.html
+
+```html
+{% extends 'layout.html' %} {% block content %}
+
+
Welcome to {{name}}
+
+ This application clean texts and analyse the number of word, characters and
+ most frequent words in the text. Check it out by click text analyzer at the
+ menu. You need the following technologies to build this web application:
+
+
+{% endblock %}
+```
+
+Request methods, there are different request methods(GET, POST, PUT, DELETE) are the common request methods which allow us to do CRUD(Create, Read, Update, Delete) operation.
+
+In the post, route we will use GET and POST method alternative depending on the type of request, check how it looks in the code below. The request method is a function to handle request methods and also to access form data.
+app.py
+
+```py
+# let's import the flask
+from flask import Flask, render_template, request, redirect, url_for
+import os # importing operating system module
+
+app = Flask(__name__)
+# to stop caching static file
+app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
+
+
+
+@app.route('/') # this decorator create the home route
+def home ():
+ techs = ['HTML', 'CSS', 'Flask', 'Python']
+ name = '30 Days Of Python Programming'
+ return render_template('home.html', techs=techs, name = name, title = 'Home')
+
+@app.route('/about')
+def about():
+ name = '30 Days Of Python Programming'
+ return render_template('about.html', name = name, title = 'About Us')
+
+@app.route('/result')
+def result():
+ return render_template('result.html')
+
+@app.route('/post', methods= ['GET','POST'])
+def post():
+ name = 'Text Analyzer'
+ if request.method == 'GET':
+ return render_template('post.html', name = name, title = name)
+ if request.method =='POST':
+ content = request.form['content']
+ print(content)
+ return redirect(url_for('result'))
+
+if __name__ == '__main__':
+ # for deployment
+ # to make it work for both production and development
+ port = int(os.environ.get("PORT", 5000))
+ app.run(debug=True, host='0.0.0.0', port=port)
+```
+
+So far, we have seen how to use template and how to inject data to template, how to a common layout.
+Now, lets handle static file. Create a folder called static in the project director and create a folder called css. Inside css folder create main.css. Your main. css file will be linked to the layout.html.
+
+You don't have to write the css file, copy and use it. Let's move on to deployment.
+
+### Deployment
+
+#### Creating Heroku account
+
+Heroku provides a free deployment service for both front end and fullstack applications. Create an account on [heroku](https://www.heroku.com/) and install the heroku [CLI](https://devcenter.heroku.com/articles/heroku-cli) for you machine.
+After installing heroku write the following command
+
+#### Login to Heroku
+
+```sh
+asabeneh@Asabeneh:~$ heroku login
+heroku: Press any key to open up the browser to login or q to exit:
+```
+
+Let's see the result by clicking any key from the keyboard. When you press any key from you keyboard it will open the heroku login page and click the login page. Then you will local machine will be connected to the remote heroku server. If you are connected to remote server, you will see this.
+
+```sh
+asabeneh@Asabeneh:~$ heroku login
+heroku: Press any key to open up the browser to login or q to exit:
+Opening browser to https://cli-auth.heroku.com/auth/browser/be12987c-583a-4458-a2c2-ba2ce7f41610
+Logging in... done
+Logged in as asabeneh@gmail.com
+asabeneh@Asabeneh:~$
+```
+
+#### Create requirements and Procfile
+
+Before we push our code to remote server, we need requirements
+
+- requirements.txt
+- Procfile
+
+```sh
+(env) asabeneh@Asabeneh:~/Desktop/python_for_web$ pip freeze
+Click==7.0
+Flask==1.1.1
+itsdangerous==1.1.0
+Jinja2==2.10.3
+MarkupSafe==1.1.1
+Werkzeug==0.16.0
+(env) asabeneh@Asabeneh:~/Desktop/python_for_web$ touch requirements.txt
+(env) asabeneh@Asabeneh:~/Desktop/python_for_web$ pip freeze > requirements.txt
+(env) asabeneh@Asabeneh:~/Desktop/python_for_web$ cat requirements.txt
+Click==7.0
+Flask==1.1.1
+itsdangerous==1.1.0
+Jinja2==2.10.3
+MarkupSafe==1.1.1
+Werkzeug==0.16.0
+(env) asabeneh@Asabeneh:~/Desktop/python_for_web$ touch Procfile
+(env) asabeneh@Asabeneh:~/Desktop/python_for_web$ ls
+Procfile env/ static/
+app.py requirements.txt templates/
+(env) asabeneh@Asabeneh:~/Desktop/python_for_web$
+```
+
+The Procfile will have the command which run the application in the web server in our case on Heroku.
+
+```sh
+web: python app.py
+```
+
+#### Pushing project to heroku
+
+Now, it is ready to be deployed. Steps to deploy the application on heroku
+
+1. git init
+2. git add .
+3. git commit -m "commit message"
+4. heroku create 'name of the app as one word'
+5. git push heroku master
+6. heroku open(to launch the deployed application)
+
+After this step you will get an application like [this](http://thirdaysofpython-practice.herokuapp.com/)
+
+## Exercises: Day 26
+
+1. You will build [this application](https://thirtydaysofpython-v1-final.herokuapp.com/). Only the text analyser part is left
+
+
+🎉 CONGRATULATIONS ! 🎉
+
+[<< Day 25 ](../25_Day_Pandas/25_pandas.md) | [Day 27 >>](../27_Day_Python_with_mongodb/27_python_with_mongodb.md)
\ No newline at end of file
diff --git a/26_python_web/index.html b/26_python_web/index.html
new file mode 100644
index 0000000..e113900
--- /dev/null
+++ b/26_python_web/index.html
@@ -0,0 +1,1947 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 26 python web - 30天入门Python全栈开发
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Python is a general purpose programming language and it can be used for many places. In this section, we will see how we use Python for the web. There are many Python web frame works. Django and Flask are the most popular ones. Today, we will see how to use Flask for web development.
Flask is a web development framework written in Python. Flask uses Jinja2 template engine. Flask can be also used with other modern front libraries such as React.
+
If you did not install the virtualenv package yet install it first. Virtual environment will allows to isolate project dependencies from the local machine dependencies.
We created a project director named python_for_web. Inside the project we created a virtual environment venv which could be any name but I prefer to call it venv. Then we activated the virtual environment. We used pip freeze to check the installed packages in the project directory. The result of pip freeze was empty because a package was not installed yet.
+
Now, let's create app.py file in the project directory and write the following code. The app.py file will be the main file in the project. The following code has flask module, os module.
# let's import the flask
+fromflaskimportFlask
+importos# importing operating system module
+
+app=Flask(__name__)
+
+@app.route('/')# this decorator create the home route
+defhome():
+ return'<h1>Welcome</h1>'
+
+@app.route('/about')
+defabout():
+ return'<h1>About us</h1>'
+
+
+if__name__=='__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port=int(os.environ.get("PORT",5000))
+ app.run(debug=True,host='0.0.0.0',port=port)
+
+
To run the flask application, write python app.py in the main flask application directory.
+
After you run python app.py check local host 5000.
+
Let us add additional route.
+Creating about route
+
# let's import the flask
+fromflaskimportFlask
+importos# importing operating system module
+
+app=Flask(__name__)
+
+@app.route('/')# this decorator create the home route
+defhome():
+ return'<h1>Welcome</h1>'
+
+@app.route('/about')
+defabout():
+ return'<h1>About us</h1>'
+
+if__name__=='__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port=int(os.environ.get("PORT",5000))
+ app.run(debug=True,host='0.0.0.0',port=port)
+
+
Now, we added the about route in the above code. How about if we want to render an HTML file instead of string? It is possible to render HTML file using the function render_templae. Let us create a folder called templates and create home.html and about.html in the project directory. Let us also import the render_template function from flask.
# let's import the flask
+fromflaskimportFlask,render_template
+importos# importing operating system module
+
+app=Flask(__name__)
+
+@app.route('/')# this decorator create the home route
+defhome():
+ returnrender_template('home.html')
+
+@app.route('/about')
+defabout():
+ returnrender_template('about.html')
+
+if__name__=='__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port=int(os.environ.get("PORT",5000))
+ app.run(debug=True,host='0.0.0.0',port=port)
+
+
As you can see to go to different pages or to navigate we need a navigation. Let's add a link to each page or let's create a layout which we use to every page.
Now, we can navigate between the pages using the above link. Let us create additional page which handle form data. You can call it any name, I like to call it post.html.
+
We can inject data to the HTML files using Jinja2 template engine.
+
# let's import the flask
+fromflaskimportFlask,render_template,request,redirect,url_for
+importos# importing operating system module
+
+app=Flask(__name__)
+
+@app.route('/')# this decorator create the home route
+defhome():
+ techs=['HTML','CSS','Flask','Python']
+ name='30 Days Of Python Programming'
+ returnrender_template('home.html',techs=techs,name=name,title='Home')
+
+@app.route('/about')
+defabout():
+ name='30 Days Of Python Programming'
+ returnrender_template('about.html',name=name,title='About Us')
+
+@app.route('/post')
+defpost():
+ name='Text Analyzer'
+ returnrender_template('post.html',name=name,title=name)
+
+
+if__name__=='__main__':
+ # for deployment
+ # to make it work for both production and development
+ port=int(os.environ.get("PORT",5000))
+ app.run(debug=True,host='0.0.0.0',port=port)
+
In the template files, there are lots of repeated codes, we can write a layout and we can remove the repetition. Let's create layout.html inside the templates folder.
+After we create the layout we will import to every file.
Create a static folder in your project directory. Inside the static folder create CSS or styles folder and create a CSS stylesheet. We use the url_for module to serve the static file.
Now, lets remove all the repeated code in the other template files and import the layout.html. The href is using url_for function with the name of the route function to connect each navigation route.
+
home.html
+
{% extends 'layout.html' %} {% block content %}
+<divclass="container">
+ <h1>Welcome to {{name}}</h1>
+ <p>
+ This application clean texts and analyse the number of word, characters and
+ most frequent words in the text. Check it out by click text analyzer at the
+ menu. You need the following technologies to build this web application:
+ </p>
+ <ulclass="tech-lists">
+ {% for tech in techs %}
+ <liclass="tech">{{tech}}</li>
+
+ {% endfor %}
+ </ul>
+</div>
+
+{% endblock %}
+
+
about.html
+
{% extends 'layout.html' %} {% block content %}
+<divclass="container">
+ <h1>About {{name}}</h1>
+ <p>
+ This is a 30 days of python programming challenge. If you have been coding
+ this far, you are awesome. Congratulations for the job well done!
+ </p>
+</div>
+{% endblock %}
+
Request methods, there are different request methods(GET, POST, PUT, DELETE) are the common request methods which allow us to do CRUD(Create, Read, Update, Delete) operation.
+
In the post, route we will use GET and POST method alternative depending on the type of request, check how it looks in the code below. The request method is a function to handle request methods and also to access form data.
+app.py
+
# let's import the flask
+fromflaskimportFlask,render_template,request,redirect,url_for
+importos# importing operating system module
+
+app=Flask(__name__)
+# to stop caching static file
+app.config['SEND_FILE_MAX_AGE_DEFAULT']=0
+
+
+
+@app.route('/')# this decorator create the home route
+defhome():
+ techs=['HTML','CSS','Flask','Python']
+ name='30 Days Of Python Programming'
+ returnrender_template('home.html',techs=techs,name=name,title='Home')
+
+@app.route('/about')
+defabout():
+ name='30 Days Of Python Programming'
+ returnrender_template('about.html',name=name,title='About Us')
+
+@app.route('/result')
+defresult():
+ returnrender_template('result.html')
+
+@app.route('/post',methods=['GET','POST'])
+defpost():
+ name='Text Analyzer'
+ ifrequest.method=='GET':
+ returnrender_template('post.html',name=name,title=name)
+ ifrequest.method=='POST':
+ content=request.form['content']
+ print(content)
+ returnredirect(url_for('result'))
+
+if__name__=='__main__':
+ # for deployment
+ # to make it work for both production and development
+ port=int(os.environ.get("PORT",5000))
+ app.run(debug=True,host='0.0.0.0',port=port)
+
+
So far, we have seen how to use template and how to inject data to template, how to a common layout.
+Now, lets handle static file. Create a folder called static in the project director and create a folder called css. Inside css folder create main.css. Your main. css file will be linked to the layout.html.
+
You don't have to write the css file, copy and use it. Let's move on to deployment.
Heroku provides a free deployment service for both front end and fullstack applications. Create an account on heroku and install the heroku CLI for you machine.
+After installing heroku write the following command
Let's see the result by clicking any key from the keyboard. When you press any key from you keyboard it will open the heroku login page and click the login page. Then you will local machine will be connected to the remote heroku server. If you are connected to remote server, you will see this.
+
+[<< Day 26](../26_Day_Python_web/26_python_web.md) | [Day 28 >>](../28_Day_API/28_API.md)
+
+![30DaysOfPython](../images/30DaysOfPython_banner3@2x.png)
+
+- [📘 Day 27](#-day-27)
+- [Python with MongoDB](#python-with-mongodb)
+ - [MongoDB](#mongodb)
+ - [SQL versus NoSQL](#sql-versus-nosql)
+ - [Getting Connection String(MongoDB URI)](#getting-connection-stringmongodb-uri)
+ - [Connecting Flask application to MongoDB Cluster](#connecting-flask-application-to-mongodb-cluster)
+ - [Creating a database and collection](#creating-a-database-and-collection)
+ - [Inserting many documents to collection](#inserting-many-documents-to-collection)
+ - [MongoDB Find](#mongodb-find)
+ - [Find with Query](#find-with-query)
+ - [Find query with modifier](#find-query-with-modifier)
+ - [Limiting documents](#limiting-documents)
+ - [Find with sort](#find-with-sort)
+ - [Update with query](#update-with-query)
+ - [Delete Document](#delete-document)
+ - [Drop a collection](#drop-a-collection)
+ - [💻 Exercises: Day 27](#-exercises-day-27)
+
+# 📘 Day 27
+
+# Python with MongoDB
+
+Python is a backend technology and it can be connected with different data base applications. It can be connected to both SQL and noSQL databases. In this section, we connect Python with MongoDB database which is noSQL database.
+
+## MongoDB
+
+MongoDB is a NoSQL database. MongoDB stores data in a JSON like document which make MongoDB very flexible and scalable. Let us see the different terminologies of SQL and NoSQL databases. The following table will make the difference between SQL versus NoSQL databases.
+
+### SQL versus NoSQL
+
+![SQL versus NoSQL](../images/mongoDB/sql-vs-nosql.png)
+
+In this section, we will focus on a NoSQL database MongoDB. Lets sign up on [mongoDB](https://www.mongodb.com/) by click on the sign in button then click register on the next page.
+
+![MongoDB Sign up pages](../images/mongoDB/mongodb-signup-page.png)
+
+Complete the fields and click continue
+
+![Mongodb register](../images/mongoDB/mongodb-register.png)
+
+Select the free plan
+
+![Mongodb free plan](../images/mongoDB/mongodb-free.png)
+
+Choose the proximate free region and give any name for you cluster.
+
+![Mongodb cluster name](../images/mongoDB/mongodb-cluster-name.png)
+
+Now, a free sandbox is created
+
+![Mongodb sandbox](../images/mongoDB/mongodb-sandbox.png)
+
+All local host access
+
+![Mongodb allow ip access](../images/mongoDB/mongodb-allow-ip-access.png)
+
+Add user and password
+
+![Mongodb add user](../images/mongoDB/mongodb-add-user.png)
+
+Create a mongoDB uri link
+
+![Mongodb create uri](../images/mongoDB/mongodb-create-uri.png)
+
+Select Python 3.6 or above driver
+
+![Mongodb python driver](../images/mongoDB/mongodb-python-driver.png)
+
+### Getting Connection String(MongoDB URI)
+
+Copy the connection string link and you will get something like this
+
+```sh
+mongodb+srv://asabeneh:@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority
+```
+
+Do not worry about the url, it is a means to connect your application with mongoDB.
+Let us replace the password placeholder with the password you used to add a user.
+
+**Example:**
+
+```sh
+mongodb+srv://asabeneh:123123123@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority
+```
+
+Now, I replaced everything and the password is 123123 and the name of the database is thirty_days_python. This is just an example, your password must be a bit stronger than this.
+
+Python needs a mongoDB driver to access mongoDB database. We will use _pymongo_ with _dnspython_ to connect our application with mongoDB base . Inside your project directory install pymongo and dnspython.
+
+```sh
+pip install pymongo dnspython
+```
+
+The "dnspython" module must be installed to use mongodb+srv:// URIs. The dnspython is a DNS toolkit for Python. It supports almost all record types.
+
+### Connecting Flask application to MongoDB Cluster
+
+```py
+# let's import the flask
+from flask import Flask, render_template
+import os # importing operating system module
+MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client = pymongo.MongoClient(MONGODB_URI)
+print(client.list_database_names())
+
+app = Flask(__name__)
+if __name__ == '__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port = int(os.environ.get("PORT", 5000))
+ app.run(debug=True, host='0.0.0.0', port=port)
+
+```
+
+When we run the above code we get the default mongoDB databases.
+
+```sh
+['admin', 'local']
+```
+
+### Creating a database and collection
+
+Let us create a database, database and collection in mongoDB will be created if it doesn't exist. Let's create a data base name _thirty_days_of_python_ and _students_ collection.
+To create a database
+
+```sh
+db = client.name_of_databse # we can create a database like this or the second way
+db = client['name_of_database']
+```
+
+```py
+# let's import the flask
+from flask import Flask, render_template
+import os # importing operating system module
+MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client = pymongo.MongoClient(MONGODB_URI)
+# Creating database
+db = client.thirty_days_of_python
+# Creating students collection and inserting a document
+db.students.insert_one({'name': 'Asabeneh', 'country': 'Finland', 'city': 'Helsinki', 'age': 250})
+print(client.list_database_names())
+
+app = Flask(__name__)
+if __name__ == '__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port = int(os.environ.get("PORT", 5000))
+ app.run(debug=True, host='0.0.0.0', port=port)
+```
+
+After we create a database, we also created a students collection and we used *insert_one()* method to insert a document.
+Now, the database *thirty_days_of_python* and *students* collection have been created and the document has been inserted.
+Check your mongoDB cluster and you will see both the database and the collection. Inside the collection, there will be a document.
+
+```sh
+['thirty_days_of_python', 'admin', 'local']
+```
+
+If you see this on the mongoDB cluster, it means you have successfully created a database and a collection.
+
+![Creating database and collection](../images/mongoDB/mongodb-creating_database.png)
+
+If you have seen on the figure, the document has been created with a long id which acts as a primary key. Every time we create a document mongoDB create and unique id for it.
+
+### Inserting many documents to collection
+
+The *insert_one()* method inserts one item at a time if we want to insert many documents at once either we use *insert_many()* method or for loop.
+We can use for loop to inset many documents at once.
+
+```py
+# let's import the flask
+from flask import Flask, render_template
+import os # importing operating system module
+MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client = pymongo.MongoClient(MONGODB_URI)
+
+students = [
+ {'name':'David','country':'UK','city':'London','age':34},
+ {'name':'John','country':'Sweden','city':'Stockholm','age':28},
+ {'name':'Sami','country':'Finland','city':'Helsinki','age':25},
+ ]
+for student in students:
+ db.students.insert_one(student)
+
+
+app = Flask(__name__)
+if __name__ == '__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port = int(os.environ.get("PORT", 5000))
+ app.run(debug=True, host='0.0.0.0', port=port)
+```
+
+### MongoDB Find
+
+The *find()* and *findOne()* methods are common method to find data in a collection in mongoDB database. It is similar to the SELECT statement in a MySQL database.
+Let us use the _find_one()_ method to get a document in a database collection.
+
+- \*find_one({"\_id": ObjectId("id"}): Gets the first occurrence if an id is not provided
+
+```py
+# let's import the flask
+from flask import Flask, render_template
+import os # importing operating system module
+MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client = pymongo.MongoClient(MONGODB_URI)
+db = client['thirty_days_of_python'] # accessing the database
+student = db.students.find_one()
+print(student)
+
+
+app = Flask(__name__)
+if __name__ == '__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port = int(os.environ.get("PORT", 5000))
+ app.run(debug=True, host='0.0.0.0', port=port)
+
+```
+
+```sh
+{'_id': ObjectId('5df68a21f106fe2d315bbc8b'), 'name': 'Asabeneh', 'country': 'Helsinki', 'city': 'Helsinki', 'age': 250}
+```
+
+The above query returns the first entry but we can target specific document using specific \_id. Let us do one example, use David's id to get David object.
+'\_id':ObjectId('5df68a23f106fe2d315bbc8c')
+
+```py
+# let's import the flask
+from flask import Flask, render_template
+import os # importing operating system module
+from bson.objectid import ObjectId # id object
+MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client = pymongo.MongoClient(MONGODB_URI)
+db = client['thirty_days_of_python'] # accessing the database
+student = db.students.find_one({'_id':ObjectId('5df68a23f106fe2d315bbc8c')})
+print(student)
+
+app = Flask(__name__)
+if __name__ == '__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port = int(os.environ.get("PORT", 5000))
+ app.run(debug=True, host='0.0.0.0', port=port)
+```
+
+```sh
+{'_id': ObjectId('5df68a23f106fe2d315bbc8c'), 'name': 'David', 'country': 'UK', 'city': 'London', 'age': 34}
+```
+
+We have seen, how to use _find_one()_ using the above examples. Let's move one to _find()_
+
+- _find()_: returns all the occurrence from a collection if we don't pass a query object. The object is pymongo.cursor object.
+
+```py
+# let's import the flask
+from flask import Flask, render_template
+import os # importing operating system module
+
+MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client = pymongo.MongoClient(MONGODB_URI)
+db = client['thirty_days_of_python'] # accessing the database
+students = db.students.find()
+for student in students:
+ print(student)
+
+app = Flask(__name__)
+if __name__ == '__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port = int(os.environ.get("PORT", 5000))
+ app.run(debug=True, host='0.0.0.0', port=port)
+```
+
+```sh
+{'_id': ObjectId('5df68a21f106fe2d315bbc8b'), 'name': 'Asabeneh', 'country': 'Finland', 'city': 'Helsinki', 'age': 250}
+{'_id': ObjectId('5df68a23f106fe2d315bbc8c'), 'name': 'David', 'country': 'UK', 'city': 'London', 'age': 34}
+{'_id': ObjectId('5df68a23f106fe2d315bbc8d'), 'name': 'John', 'country': 'Sweden', 'city': 'Stockholm', 'age': 28}
+{'_id': ObjectId('5df68a23f106fe2d315bbc8e'), 'name': 'Sami', 'country': 'Finland', 'city': 'Helsinki', 'age': 25}
+```
+
+We can specify which fields to return by passing second object in the _find({}, {})_. 0 means not include and 1 means include but we can not mix 0 and 1, except for \_id.
+
+```py
+# let's import the flask
+from flask import Flask, render_template
+import os # importing operating system module
+
+MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client = pymongo.MongoClient(MONGODB_URI)
+db = client['thirty_days_of_python'] # accessing the database
+students = db.students.find({}, {"_id":0, "name": 1, "country":1}) # 0 means not include and 1 means include
+for student in students:
+ print(student)
+
+app = Flask(__name__)
+if __name__ == '__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port = int(os.environ.get("PORT", 5000))
+ app.run(debug=True, host='0.0.0.0', port=port)
+```
+
+```sh
+{'name': 'Asabeneh', 'country': 'Finland'}
+{'name': 'David', 'country': 'UK'}
+{'name': 'John', 'country': 'Sweden'}
+{'name': 'Sami', 'country': 'Finland'}
+```
+
+### Find with Query
+
+In mongoDB find take a query object. We can pass a query object and we can filter the documents we like to filter out.
+
+```py
+# let's import the flask
+from flask import Flask, render_template
+import os # importing operating system module
+
+MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client = pymongo.MongoClient(MONGODB_URI)
+db = client['thirty_days_of_python'] # accessing the database
+
+query = {
+ "country":"Finland"
+}
+students = db.students.find(query)
+
+for student in students:
+ print(student)
+
+
+app = Flask(__name__)
+if __name__ == '__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port = int(os.environ.get("PORT", 5000))
+ app.run(debug=True, host='0.0.0.0', port=port)
+```
+
+```sh
+{'_id': ObjectId('5df68a21f106fe2d315bbc8b'), 'name': 'Asabeneh', 'country': 'Finland', 'city': 'Helsinki', 'age': 250}
+{'_id': ObjectId('5df68a23f106fe2d315bbc8e'), 'name': 'Sami', 'country': 'Finland', 'city': 'Helsinki', 'age': 25}
+```
+
+Query with modifiers
+
+```py
+# let's import the flask
+from flask import Flask, render_template
+import os # importing operating system module
+import pymongo
+
+MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client = pymongo.MongoClient(MONGODB_URI)
+db = client['thirty_days_of_python'] # accessing the database
+
+query = {
+ "city":"Helsinki"
+}
+students = db.students.find(query)
+for student in students:
+ print(student)
+
+
+app = Flask(__name__)
+if __name__ == '__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port = int(os.environ.get("PORT", 5000))
+ app.run(debug=True, host='0.0.0.0', port=port)
+```
+
+```sh
+{'_id': ObjectId('5df68a21f106fe2d315bbc8b'), 'name': 'Asabeneh', 'country': 'Finland', 'city': 'Helsinki', 'age': 250}
+{'_id': ObjectId('5df68a23f106fe2d315bbc8e'), 'name': 'Sami', 'country': 'Finland', 'city': 'Helsinki', 'age': 25}
+```
+
+### Find query with modifier
+
+```py
+# let's import the flask
+from flask import Flask, render_template
+import os # importing operating system module
+import pymongo
+
+MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client = pymongo.MongoClient(MONGODB_URI)
+db = client['thirty_days_of_python'] # accessing the database
+query = {
+ "country":"Finland",
+ "city":"Helsinki"
+}
+students = db.students.find(query)
+for student in students:
+ print(student)
+
+
+app = Flask(__name__)
+if __name__ == '__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port = int(os.environ.get("PORT", 5000))
+ app.run(debug=True, host='0.0.0.0', port=port)
+```
+
+```sh
+{'_id': ObjectId('5df68a21f106fe2d315bbc8b'), 'name': 'Asabeneh', 'country': 'Finland', 'city': 'Helsinki', 'age': 250}
+{'_id': ObjectId('5df68a23f106fe2d315bbc8e'), 'name': 'Sami', 'country': 'Finland', 'city': 'Helsinki', 'age': 25}
+```
+
+Query with modifiers
+
+```py
+# let's import the flask
+from flask import Flask, render_template
+import os # importing operating system module
+import pymongo
+
+MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client = pymongo.MongoClient(MONGODB_URI)
+db = client['thirty_days_of_python'] # accessing the database
+query = {"age":{"$gt":30}}
+students = db.students.find(query)
+for student in students:
+ print(student)
+
+app = Flask(__name__)
+if __name__ == '__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port = int(os.environ.get("PORT", 5000))
+ app.run(debug=True, host='0.0.0.0', port=port)
+```
+
+```sh
+{'_id': ObjectId('5df68a21f106fe2d315bbc8b'), 'name': 'Asabeneh', 'country': 'Finland', 'city': 'Helsinki', 'age': 250}
+{'_id': ObjectId('5df68a23f106fe2d315bbc8c'), 'name': 'David', 'country': 'UK', 'city': 'London', 'age': 34}
+```
+
+```py
+# let's import the flask
+from flask import Flask, render_template
+import os # importing operating system module
+import pymongo
+
+MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client = pymongo.MongoClient(MONGODB_URI)
+db = client['thirty_days_of_python'] # accessing the database
+query = {"age":{"$gt":30}}
+students = db.students.find(query)
+for student in students:
+ print(student)
+```
+
+```sh
+{'_id': ObjectId('5df68a23f106fe2d315bbc8d'), 'name': 'John', 'country': 'Sweden', 'city': 'Stockholm', 'age': 28}
+{'_id': ObjectId('5df68a23f106fe2d315bbc8e'), 'name': 'Sami', 'country': 'Finland', 'city': 'Helsinki', 'age': 25}
+```
+
+### Limiting documents
+
+We can limit the number of documents we return using the _limit()_ method.
+
+```py
+# let's import the flask
+from flask import Flask, render_template
+import os # importing operating system module
+import pymongo
+
+MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client = pymongo.MongoClient(MONGODB_URI)
+db = client['thirty_days_of_python'] # accessing the database
+db.students.find().limit(3)
+```
+
+### Find with sort
+
+By default, sort is in ascending order. We can change the sorting to descending order by adding -1 parameter.
+
+```py
+# let's import the flask
+from flask import Flask, render_template
+import os # importing operating system module
+import pymongo
+
+MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client = pymongo.MongoClient(MONGODB_URI)
+db = client['thirty_days_of_python'] # accessing the database
+students = db.students.find().sort('name')
+for student in students:
+ print(student)
+
+
+students = db.students.find().sort('name',-1)
+for student in students:
+ print(student)
+
+students = db.students.find().sort('age')
+for student in students:
+ print(student)
+
+students = db.students.find().sort('age',-1)
+for student in students:
+ print(student)
+
+app = Flask(__name__)
+if __name__ == '__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port = int(os.environ.get("PORT", 5000))
+ app.run(debug=True, host='0.0.0.0', port=port)
+```
+
+Ascending order
+
+```sh
+{'_id': ObjectId('5df68a21f106fe2d315bbc8b'), 'name': 'Asabeneh', 'country': 'Finland', 'city': 'Helsinki', 'age': 250}
+{'_id': ObjectId('5df68a23f106fe2d315bbc8c'), 'name': 'David', 'country': 'UK', 'city': 'London', 'age': 34}
+{'_id': ObjectId('5df68a23f106fe2d315bbc8d'), 'name': 'John', 'country': 'Sweden', 'city': 'Stockholm', 'age': 28}
+{'_id': ObjectId('5df68a23f106fe2d315bbc8e'), 'name': 'Sami', 'country': 'Finland', 'city': 'Helsinki', 'age': 25}
+```
+
+Descending order
+
+```sh
+{'_id': ObjectId('5df68a23f106fe2d315bbc8e'), 'name': 'Sami', 'country': 'Finland', 'city': 'Helsinki', 'age': 25}
+{'_id': ObjectId('5df68a23f106fe2d315bbc8d'), 'name': 'John', 'country': 'Sweden', 'city': 'Stockholm', 'age': 28}
+{'_id': ObjectId('5df68a23f106fe2d315bbc8c'), 'name': 'David', 'country': 'UK', 'city': 'London', 'age': 34}
+{'_id': ObjectId('5df68a21f106fe2d315bbc8b'), 'name': 'Asabeneh', 'country': 'Finland', 'city': 'Helsinki', 'age': 250}
+```
+
+### Update with query
+
+We will use *update_one()* method to update one item. It takes two object one is a query and the second is the new object.
+The first person, Asabeneh got a very implausible age. Let us update Asabeneh's age.
+
+```py
+# let's import the flask
+from flask import Flask, render_template
+import os # importing operating system module
+import pymongo
+
+MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client = pymongo.MongoClient(MONGODB_URI)
+db = client['thirty_days_of_python'] # accessing the database
+
+query = {'age':250}
+new_value = {'$set':{'age':38}}
+
+db.students.update_one(query, new_value)
+# lets check the result if the age is modified
+for student in db.students.find():
+ print(student)
+
+
+app = Flask(__name__)
+if __name__ == '__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port = int(os.environ.get("PORT", 5000))
+ app.run(debug=True, host='0.0.0.0', port=port)
+```
+
+```sh
+{'_id': ObjectId('5df68a21f106fe2d315bbc8b'), 'name': 'Asabeneh', 'country': 'Finland', 'city': 'Helsinki', 'age': 38}
+{'_id': ObjectId('5df68a23f106fe2d315bbc8c'), 'name': 'David', 'country': 'UK', 'city': 'London', 'age': 34}
+{'_id': ObjectId('5df68a23f106fe2d315bbc8d'), 'name': 'John', 'country': 'Sweden', 'city': 'Stockholm', 'age': 28}
+{'_id': ObjectId('5df68a23f106fe2d315bbc8e'), 'name': 'Sami', 'country': 'Finland', 'city': 'Helsinki', 'age': 25}
+```
+
+When we want to update many documents at once we use *upate_many()* method.
+
+### Delete Document
+
+The method *delete_one()* deletes one document. The *delete_one()* takes a query object parameter. It only removes the first occurrence.
+Let us remove one John from the collection.
+
+```py
+# let's import the flask
+from flask import Flask, render_template
+import os # importing operating system module
+import pymongo
+
+MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client = pymongo.MongoClient(MONGODB_URI)
+db = client['thirty_days_of_python'] # accessing the database
+
+query = {'name':'John'}
+db.students.delete_one(query)
+
+for student in db.students.find():
+ print(student)
+# lets check the result if the age is modified
+for student in db.students.find():
+ print(student)
+
+
+app = Flask(__name__)
+if __name__ == '__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port = int(os.environ.get("PORT", 5000))
+ app.run(debug=True, host='0.0.0.0', port=port)
+```
+
+```sh
+{'_id': ObjectId('5df68a21f106fe2d315bbc8b'), 'name': 'Asabeneh', 'country': 'Finland', 'city': 'Helsinki', 'age': 38}
+{'_id': ObjectId('5df68a23f106fe2d315bbc8c'), 'name': 'David', 'country': 'UK', 'city': 'London', 'age': 34}
+{'_id': ObjectId('5df68a23f106fe2d315bbc8e'), 'name': 'Sami', 'country': 'Finland', 'city': 'Helsinki', 'age': 25}
+```
+
+As you can see John has been removed from the collection.
+
+When we want to delete many documents we use *delete_many()* method, it takes a query object. If we pass an empty query object to *delete_many({})* it will delete all the documents in the collection.
+
+### Drop a collection
+
+Using the _drop()_ method we can delete a collection from a database.
+
+```py
+# let's import the flask
+from flask import Flask, render_template
+import os # importing operating system module
+import pymongo
+
+MONGODB_URI = 'mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client = pymongo.MongoClient(MONGODB_URI)
+db = client['thirty_days_of_python'] # accessing the database
+db.students.drop()
+```
+
+Now, we have deleted the students collection from the database.
+
+## 💻 Exercises: Day 27
+
+🎉 CONGRATULATIONS ! 🎉
+
+[<< Day 26](../26_Day_Python_web/26_python_web.md) | [Day 28 >>](../28_Day_API/28_API.md)
diff --git a/27_python_with_mongodb/index.html b/27_python_with_mongodb/index.html
new file mode 100644
index 0000000..5b02659
--- /dev/null
+++ b/27_python_with_mongodb/index.html
@@ -0,0 +1,1615 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 27 python with mongodb - 30天入门Python全栈开发
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Python is a backend technology and it can be connected with different data base applications. It can be connected to both SQL and noSQL databases. In this section, we connect Python with MongoDB database which is noSQL database.
MongoDB is a NoSQL database. MongoDB stores data in a JSON like document which make MongoDB very flexible and scalable. Let us see the different terminologies of SQL and NoSQL databases. The following table will make the difference between SQL versus NoSQL databases.
In this section, we will focus on a NoSQL database MongoDB. Lets sign up on mongoDB by click on the sign in button then click register on the next page.
+
+
Complete the fields and click continue
+
+
Select the free plan
+
+
Choose the proximate free region and give any name for you cluster.
Do not worry about the url, it is a means to connect your application with mongoDB.
+Let us replace the password placeholder with the password you used to add a user.
Now, I replaced everything and the password is 123123 and the name of the database is thirty_days_python. This is just an example, your password must be a bit stronger than this.
+
Python needs a mongoDB driver to access mongoDB database. We will use pymongo with dnspython to connect our application with mongoDB base . Inside your project directory install pymongo and dnspython.
+
pipinstallpymongodnspython
+
+
The "dnspython" module must be installed to use mongodb+srv:// URIs. The dnspython is a DNS toolkit for Python. It supports almost all record types.
# let's import the flask
+fromflaskimportFlask,render_template
+importos# importing operating system module
+MONGODB_URI='mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client=pymongo.MongoClient(MONGODB_URI)
+print(client.list_database_names())
+
+app=Flask(__name__)
+if__name__=='__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port=int(os.environ.get("PORT",5000))
+ app.run(debug=True,host='0.0.0.0',port=port)
+
+
When we run the above code we get the default mongoDB databases.
Let us create a database, database and collection in mongoDB will be created if it doesn't exist. Let's create a data base name thirty_days_of_python and students collection.
+To create a database
+
db=client.name_of_databse# we can create a database like this or the second way
+db=client['name_of_database']
+
+
# let's import the flask
+fromflaskimportFlask,render_template
+importos# importing operating system module
+MONGODB_URI='mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client=pymongo.MongoClient(MONGODB_URI)
+# Creating database
+db=client.thirty_days_of_python
+# Creating students collection and inserting a document
+db.students.insert_one({'name':'Asabeneh','country':'Finland','city':'Helsinki','age':250})
+print(client.list_database_names())
+
+app=Flask(__name__)
+if__name__=='__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port=int(os.environ.get("PORT",5000))
+ app.run(debug=True,host='0.0.0.0',port=port)
+
+
After we create a database, we also created a students collection and we used insert_one() method to insert a document.
+Now, the database thirty_days_of_python and students collection have been created and the document has been inserted.
+Check your mongoDB cluster and you will see both the database and the collection. Inside the collection, there will be a document.
+
['thirty_days_of_python','admin','local']
+
+
If you see this on the mongoDB cluster, it means you have successfully created a database and a collection.
+
+
If you have seen on the figure, the document has been created with a long id which acts as a primary key. Every time we create a document mongoDB create and unique id for it.
The insert_one() method inserts one item at a time if we want to insert many documents at once either we use insert_many() method or for loop.
+We can use for loop to inset many documents at once.
+
# let's import the flask
+fromflaskimportFlask,render_template
+importos# importing operating system module
+MONGODB_URI='mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client=pymongo.MongoClient(MONGODB_URI)
+
+students=[
+ {'name':'David','country':'UK','city':'London','age':34},
+ {'name':'John','country':'Sweden','city':'Stockholm','age':28},
+ {'name':'Sami','country':'Finland','city':'Helsinki','age':25},
+ ]
+forstudentinstudents:
+ db.students.insert_one(student)
+
+
+app=Flask(__name__)
+if__name__=='__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port=int(os.environ.get("PORT",5000))
+ app.run(debug=True,host='0.0.0.0',port=port)
+
The find() and findOne() methods are common method to find data in a collection in mongoDB database. It is similar to the SELECT statement in a MySQL database.
+Let us use the find_one() method to get a document in a database collection.
+
+
*find_one({"_id": ObjectId("id"}): Gets the first occurrence if an id is not provided
+
+
# let's import the flask
+fromflaskimportFlask,render_template
+importos# importing operating system module
+MONGODB_URI='mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client=pymongo.MongoClient(MONGODB_URI)
+db=client['thirty_days_of_python']# accessing the database
+student=db.students.find_one()
+print(student)
+
+
+app=Flask(__name__)
+if__name__=='__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port=int(os.environ.get("PORT",5000))
+ app.run(debug=True,host='0.0.0.0',port=port)
+
The above query returns the first entry but we can target specific document using specific _id. Let us do one example, use David's id to get David object.
+'_id':ObjectId('5df68a23f106fe2d315bbc8c')
+
# let's import the flask
+fromflaskimportFlask,render_template
+importos# importing operating system module
+frombson.objectidimportObjectId# id object
+MONGODB_URI='mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client=pymongo.MongoClient(MONGODB_URI)
+db=client['thirty_days_of_python']# accessing the database
+student=db.students.find_one({'_id':ObjectId('5df68a23f106fe2d315bbc8c')})
+print(student)
+
+app=Flask(__name__)
+if__name__=='__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port=int(os.environ.get("PORT",5000))
+ app.run(debug=True,host='0.0.0.0',port=port)
+
We have seen, how to use find_one() using the above examples. Let's move one to find()
+
+
find(): returns all the occurrence from a collection if we don't pass a query object. The object is pymongo.cursor object.
+
+
# let's import the flask
+fromflaskimportFlask,render_template
+importos# importing operating system module
+
+MONGODB_URI='mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client=pymongo.MongoClient(MONGODB_URI)
+db=client['thirty_days_of_python']# accessing the database
+students=db.students.find()
+forstudentinstudents:
+ print(student)
+
+app=Flask(__name__)
+if__name__=='__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port=int(os.environ.get("PORT",5000))
+ app.run(debug=True,host='0.0.0.0',port=port)
+
We can specify which fields to return by passing second object in the find({}, {}). 0 means not include and 1 means include but we can not mix 0 and 1, except for _id.
+
# let's import the flask
+fromflaskimportFlask,render_template
+importos# importing operating system module
+
+MONGODB_URI='mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client=pymongo.MongoClient(MONGODB_URI)
+db=client['thirty_days_of_python']# accessing the database
+students=db.students.find({},{"_id":0,"name":1,"country":1})# 0 means not include and 1 means include
+forstudentinstudents:
+ print(student)
+
+app=Flask(__name__)
+if__name__=='__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port=int(os.environ.get("PORT",5000))
+ app.run(debug=True,host='0.0.0.0',port=port)
+
In mongoDB find take a query object. We can pass a query object and we can filter the documents we like to filter out.
+
# let's import the flask
+fromflaskimportFlask,render_template
+importos# importing operating system module
+
+MONGODB_URI='mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client=pymongo.MongoClient(MONGODB_URI)
+db=client['thirty_days_of_python']# accessing the database
+
+query={
+ "country":"Finland"
+}
+students=db.students.find(query)
+
+forstudentinstudents:
+ print(student)
+
+
+app=Flask(__name__)
+if__name__=='__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port=int(os.environ.get("PORT",5000))
+ app.run(debug=True,host='0.0.0.0',port=port)
+
# let's import the flask
+fromflaskimportFlask,render_template
+importos# importing operating system module
+importpymongo
+
+MONGODB_URI='mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client=pymongo.MongoClient(MONGODB_URI)
+db=client['thirty_days_of_python']# accessing the database
+
+query={
+ "city":"Helsinki"
+}
+students=db.students.find(query)
+forstudentinstudents:
+ print(student)
+
+
+app=Flask(__name__)
+if__name__=='__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port=int(os.environ.get("PORT",5000))
+ app.run(debug=True,host='0.0.0.0',port=port)
+
# let's import the flask
+fromflaskimportFlask,render_template
+importos# importing operating system module
+importpymongo
+
+MONGODB_URI='mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client=pymongo.MongoClient(MONGODB_URI)
+db=client['thirty_days_of_python']# accessing the database
+query={
+ "country":"Finland",
+ "city":"Helsinki"
+}
+students=db.students.find(query)
+forstudentinstudents:
+ print(student)
+
+
+app=Flask(__name__)
+if__name__=='__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port=int(os.environ.get("PORT",5000))
+ app.run(debug=True,host='0.0.0.0',port=port)
+
# let's import the flask
+fromflaskimportFlask,render_template
+importos# importing operating system module
+importpymongo
+
+MONGODB_URI='mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client=pymongo.MongoClient(MONGODB_URI)
+db=client['thirty_days_of_python']# accessing the database
+query={"age":{"$gt":30}}
+students=db.students.find(query)
+forstudentinstudents:
+ print(student)
+
+app=Flask(__name__)
+if__name__=='__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port=int(os.environ.get("PORT",5000))
+ app.run(debug=True,host='0.0.0.0',port=port)
+
By default, sort is in ascending order. We can change the sorting to descending order by adding -1 parameter.
+
# let's import the flask
+fromflaskimportFlask,render_template
+importos# importing operating system module
+importpymongo
+
+MONGODB_URI='mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client=pymongo.MongoClient(MONGODB_URI)
+db=client['thirty_days_of_python']# accessing the database
+students=db.students.find().sort('name')
+forstudentinstudents:
+ print(student)
+
+
+students=db.students.find().sort('name',-1)
+forstudentinstudents:
+ print(student)
+
+students=db.students.find().sort('age')
+forstudentinstudents:
+ print(student)
+
+students=db.students.find().sort('age',-1)
+forstudentinstudents:
+ print(student)
+
+app=Flask(__name__)
+if__name__=='__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port=int(os.environ.get("PORT",5000))
+ app.run(debug=True,host='0.0.0.0',port=port)
+
We will use update_one() method to update one item. It takes two object one is a query and the second is the new object.
+The first person, Asabeneh got a very implausible age. Let us update Asabeneh's age.
+
# let's import the flask
+fromflaskimportFlask,render_template
+importos# importing operating system module
+importpymongo
+
+MONGODB_URI='mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client=pymongo.MongoClient(MONGODB_URI)
+db=client['thirty_days_of_python']# accessing the database
+
+query={'age':250}
+new_value={'$set':{'age':38}}
+
+db.students.update_one(query,new_value)
+# lets check the result if the age is modified
+forstudentindb.students.find():
+ print(student)
+
+
+app=Flask(__name__)
+if__name__=='__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port=int(os.environ.get("PORT",5000))
+ app.run(debug=True,host='0.0.0.0',port=port)
+
The method delete_one() deletes one document. The delete_one() takes a query object parameter. It only removes the first occurrence.
+Let us remove one John from the collection.
+
# let's import the flask
+fromflaskimportFlask,render_template
+importos# importing operating system module
+importpymongo
+
+MONGODB_URI='mongodb+srv://asabeneh:your_password_goes_here@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client=pymongo.MongoClient(MONGODB_URI)
+db=client['thirty_days_of_python']# accessing the database
+
+query={'name':'John'}
+db.students.delete_one(query)
+
+forstudentindb.students.find():
+ print(student)
+# lets check the result if the age is modified
+forstudentindb.students.find():
+ print(student)
+
+
+app=Flask(__name__)
+if__name__=='__main__':
+ # for deployment we use the environ
+ # to make it work for both production and development
+ port=int(os.environ.get("PORT",5000))
+ app.run(debug=True,host='0.0.0.0',port=port)
+
As you can see John has been removed from the collection.
+
When we want to delete many documents we use delete_many() method, it takes a query object. If we pass an empty query object to delete_many({}) it will delete all the documents in the collection.
+
+
+[<< Day 27](../27_Day_Python_with_mongodb/27_python_with_mongodb.md) | [Day 29 >>](../29_Day_Building_API/29_building_API.md)
+
+![30DaysOfPython](../images/30DaysOfPython_banner3@2x.png)
+
+- [📘 Day 28](#-day-28)
+- [Application Programming Interface(API)](#application-programming-interfaceapi)
+ - [API](#api)
+ - [Building API](#building-api)
+ - [HTTP(Hypertext Transfer Protocol)](#httphypertext-transfer-protocol)
+ - [Structure of HTTP](#structure-of-http)
+ - [Initial Request Line(Status Line)](#initial-request-linestatus-line)
+ - [Initial Response Line(Status Line)](#initial-response-linestatus-line)
+ - [Header Fields](#header-fields)
+ - [The message body](#the-message-body)
+ - [Request Methods](#request-methods)
+ - [💻 Exercises: Day 28](#-exercises-day-28)
+
+# 📘 Day 28
+
+# Application Programming Interface(API)
+
+## API
+
+API stands for Application Programming Interface. The kind of API we will cover in this section is going to be Web APIs.
+Web APIs are the defined interfaces through which interactions happen between an enterprise and applications that use its assets, which also is a Service Level Agreement (SLA) to specify the functional provider and expose the service path or URL for its API users.
+
+In the context of web development, an API is defined as a set of specifications, such as Hypertext Transfer Protocol (HTTP) request messages, along with a definition of the structure of response messages, usually in an XML or a JavaScript Object Notation (JSON) format.
+
+Web API has been moving away from Simple Object Access Protocol (SOAP) based web services and service-oriented architecture (SOA) towards more direct representational state transfer (REST) style web resources.
+
+Social media services, web APIs have allowed web communities to share content and data between communities and different platforms.
+
+Using API, content that is created in one place dynamically can be posted and updated to multiple locations on the web.
+
+For example, Twitter's REST API allows developers to access core Twitter data and the Search API provides methods for developers to interact with Twitter Search and trends data.
+
+Many applications provide API end points. Some examples of API such as the countries [API](https://restcountries.eu/rest/v2/all), [cat's breed API](https://api.thecatapi.com/v1/breeds).
+
+In this section, we will cover a RESTful API that uses HTTP request methods to GET, PUT, POST and DELETE data.
+
+## Building API
+
+RESTful API is an application program interface (API) that uses HTTP requests to GET, PUT, POST and DELETE data. In the previous sections, we have learned about python, flask and mongoDB. We will use the knowledge we acquire to develop a RESTful API using Python flask and mongoDB database. Every application which has CRUD(Create, Read, Update, Delete) operation has an API to create data, to get data, to update data or to delete data from a database.
+
+To build an API, it is good to understand HTTP protocol and HTTP request and response cycle.
+
+## HTTP(Hypertext Transfer Protocol)
+
+HTTP is an established communication protocol between a client and a server. A client in this case is a browser and server is the place where you access data. HTTP is a network protocol used to deliver resources which could be files on the World Wide Web, whether they are HTML files, image files, query results, scripts, or other file types.
+
+A browser is an HTTP client because it sends requests to an HTTP server (Web server), which then sends responses back to the client.
+
+## Structure of HTTP
+
+HTTP uses client-server model. An HTTP client opens a connection and sends a request message to an HTTP server and the HTTP server returns response message which is the requested resources. When the request response cycle completes the server closes the connection.
+
+![HTTP request response cycle](../images/http_request_response_cycle.png)
+
+The format of the request and response messages are similar. Both kinds of messages have
+
+- an initial line,
+- zero or more header lines,
+- a blank line (i.e. a CRLF by itself), and
+- an optional message body (e.g. a file, or query data, or query output).
+
+Let us an example of request and response messages by navigating this site:https://thirtydaysofpython-v1-final.herokuapp.com/. This site has been deployed on Heroku free dyno and in some months may not work because of high request. Support this work to make the server run all the time.
+
+![Request and Response header](../images/request_response_header.png)
+
+## Initial Request Line(Status Line)
+
+The initial request line is different from the response.
+A request line has three parts, separated by spaces:
+
+- method name(GET, POST, HEAD)
+- path of the requested resource,
+- the version of HTTP being used. eg GET / HTTP/1.1
+
+GET is the most common HTTP that helps to get or read resource and POST is a common request method to create resource.
+
+### Initial Response Line(Status Line)
+
+The initial response line, called the status line, also has three parts separated by spaces:
+
+- HTTP version
+- Response status code that gives the result of the request, and a reason which describes the status code. Example of status lines are:
+ HTTP/1.0 200 OK
+ or
+ HTTP/1.0 404 Not Found
+ Notes:
+
+The most common status codes are:
+200 OK: The request succeeded, and the resulting resource (e.g. file or script output) is returned in the message body.
+500 Server Error
+A complete list of HTTP status code can be found [here](https://httpstatuses.com/). It can be also found [here](https://httpstatusdogs.com/).
+
+### Header Fields
+
+As you have seen in the above screenshot, header lines provide information about the request or response, or about the object sent in the message body.
+
+```sh
+GET / HTTP/1.1
+Host: thirtydaysofpython-v1-final.herokuapp.com
+Connection: keep-alive
+Pragma: no-cache
+Cache-Control: no-cache
+Upgrade-Insecure-Requests: 1
+User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36
+Sec-Fetch-User: ?1
+Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
+Sec-Fetch-Site: same-origin
+Sec-Fetch-Mode: navigate
+Referer: https://thirtydaysofpython-v1-final.herokuapp.com/post
+Accept-Encoding: gzip, deflate, br
+Accept-Language: en-GB,en;q=0.9,fi-FI;q=0.8,fi;q=0.7,en-CA;q=0.6,en-US;q=0.5,fr;q=0.4
+```
+
+### The message body
+
+An HTTP message may have a body of data sent after the header lines. In a response, this is where the requested resource is returned to the client (the most common use of the message body), or perhaps explanatory text if there's an error. In a request, this is where user-entered data or uploaded files are sent to the server.
+
+If an HTTP message includes a body, there are usually header lines in the message that describe the body. In particular,
+
+The Content-Type: header gives the MIME-type of the data in the body(text/html, application/json, text/plain, text/css, image/gif).
+The Content-Length: header gives the number of bytes in the body.
+
+### Request Methods
+
+The GET, POST, PUT and DELETE are the HTTP request methods which we are going to implement an API or a CRUD operation application.
+
+1. GET: GET method is used to retrieve and get information from the given server using a given URI. Requests using GET should only retrieve data and should have no other effect on the data.
+
+2. POST: POST request is used to create data and send data to the server, for example, creating a new post, file upload, etc. using HTML forms.
+
+3. PUT: Replaces all current representations of the target resource with the uploaded content and we use it modify or update data.
+
+4. DELETE: Removes data
+
+## 💻 Exercises: Day 28
+
+1. Read about API and HTTP
+
+🎉 CONGRATULATIONS ! 🎉
+
+[<< Day 27](../27_Day_Python_with_mongodb/27_python_with_mongodb.md) | [Day 29 >>](../29_Day_Building_API/29_building_API.md)
diff --git a/28_API/index.html b/28_API/index.html
new file mode 100644
index 0000000..bc713f3
--- /dev/null
+++ b/28_API/index.html
@@ -0,0 +1,1228 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 28 API - 30天入门Python全栈开发
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
API stands for Application Programming Interface. The kind of API we will cover in this section is going to be Web APIs.
+Web APIs are the defined interfaces through which interactions happen between an enterprise and applications that use its assets, which also is a Service Level Agreement (SLA) to specify the functional provider and expose the service path or URL for its API users.
+
In the context of web development, an API is defined as a set of specifications, such as Hypertext Transfer Protocol (HTTP) request messages, along with a definition of the structure of response messages, usually in an XML or a JavaScript Object Notation (JSON) format.
+
Web API has been moving away from Simple Object Access Protocol (SOAP) based web services and service-oriented architecture (SOA) towards more direct representational state transfer (REST) style web resources.
+
Social media services, web APIs have allowed web communities to share content and data between communities and different platforms.
+
Using API, content that is created in one place dynamically can be posted and updated to multiple locations on the web.
+
For example, Twitter's REST API allows developers to access core Twitter data and the Search API provides methods for developers to interact with Twitter Search and trends data.
+
Many applications provide API end points. Some examples of API such as the countries API, cat's breed API.
+
In this section, we will cover a RESTful API that uses HTTP request methods to GET, PUT, POST and DELETE data.
RESTful API is an application program interface (API) that uses HTTP requests to GET, PUT, POST and DELETE data. In the previous sections, we have learned about python, flask and mongoDB. We will use the knowledge we acquire to develop a RESTful API using Python flask and mongoDB database. Every application which has CRUD(Create, Read, Update, Delete) operation has an API to create data, to get data, to update data or to delete data from a database.
+
To build an API, it is good to understand HTTP protocol and HTTP request and response cycle.
HTTP is an established communication protocol between a client and a server. A client in this case is a browser and server is the place where you access data. HTTP is a network protocol used to deliver resources which could be files on the World Wide Web, whether they are HTML files, image files, query results, scripts, or other file types.
+
A browser is an HTTP client because it sends requests to an HTTP server (Web server), which then sends responses back to the client.
HTTP uses client-server model. An HTTP client opens a connection and sends a request message to an HTTP server and the HTTP server returns response message which is the requested resources. When the request response cycle completes the server closes the connection.
+
+
The format of the request and response messages are similar. Both kinds of messages have
+
+
an initial line,
+
zero or more header lines,
+
a blank line (i.e. a CRLF by itself), and
+
an optional message body (e.g. a file, or query data, or query output).
+
+
Let us an example of request and response messages by navigating this site:https://thirtydaysofpython-v1-final.herokuapp.com/. This site has been deployed on Heroku free dyno and in some months may not work because of high request. Support this work to make the server run all the time.
The initial response line, called the status line, also has three parts separated by spaces:
+
+
HTTP version
+
Response status code that gives the result of the request, and a reason which describes the status code. Example of status lines are:
+ HTTP/1.0 200 OK
+ or
+ HTTP/1.0 404 Not Found
+ Notes:
+
+
The most common status codes are:
+200 OK: The request succeeded, and the resulting resource (e.g. file or script output) is returned in the message body.
+500 Server Error
+A complete list of HTTP status code can be found here. It can be also found here.
As you have seen in the above screenshot, header lines provide information about the request or response, or about the object sent in the message body.
An HTTP message may have a body of data sent after the header lines. In a response, this is where the requested resource is returned to the client (the most common use of the message body), or perhaps explanatory text if there's an error. In a request, this is where user-entered data or uploaded files are sent to the server.
+
If an HTTP message includes a body, there are usually header lines in the message that describe the body. In particular,
+
The Content-Type: header gives the MIME-type of the data in the body(text/html, application/json, text/plain, text/css, image/gif).
+The Content-Length: header gives the number of bytes in the body.
The GET, POST, PUT and DELETE are the HTTP request methods which we are going to implement an API or a CRUD operation application.
+
+
+
GET: GET method is used to retrieve and get information from the given server using a given URI. Requests using GET should only retrieve data and should have no other effect on the data.
+
+
+
POST: POST request is used to create data and send data to the server, for example, creating a new post, file upload, etc. using HTML forms.
+
+
+
PUT: Replaces all current representations of the target resource with the uploaded content and we use it modify or update data.
+
+[<< Day 28](../28_Day_API/28_API.md) | [Day 29 >>](../30_Day_Conclusions/30_conclusions.md)
+
+![30DaysOfPython](../images/30DaysOfPython_banner3@2x.png)
+
+- [Day 29](#day-29)
+- [Building API](#building-api)
+ - [Structure of an API](#structure-of-an-api)
+ - [Retrieving data using get](#retrieving-data-using-get)
+ - [Getting a document by id](#getting-a-document-by-id)
+ - [Creating data using POST](#creating-data-using-post)
+ - [Updating using PUT](#updating-using-put)
+ - [Deleting a document using Delete](#deleting-a-document-using-delete)
+- [💻 Exercises: Day 29](#-exercises-day-29)
+
+## Day 29
+
+## Building API
+
+
+In this section, we will cove a RESTful API that uses HTTP request methods to GET, PUT, POST and DELETE data.
+
+RESTful API is an application program interface (API) that uses HTTP requests to GET, PUT, POST and DELETE data. In the previous sections, we have learned about python, flask and mongoDB. We will use the knowledge we acquire to develop a RESTful API using python flask and mongoDB. Every application which has CRUD(Create, Read, Update, Delete) operation has an API to create data, to get data, to update data or to delete data from database.
+
+The browser can handle only get request. Therefore, we have to have a tool which can help us to handle all request methods(GET, POST, PUT, DELETE).
+
+Examples of API
+
+- Countries API: https://restcountries.eu/rest/v2/all
+- Cats breed API: https://api.thecatapi.com/v1/breeds
+
+[Postman](https://www.getpostman.com/) is a very popular tool when it comes to API development. So, if you like to do this section you need to [download postman](https://www.getpostman.com/). An alternative of Postman is [Insomnia](https://insomnia.rest/download).
+
+![Postman](../images/postman.png)
+
+### Structure of an API
+
+An API end point is a URL which can help to retrieve, create, update or delete a resource. The structure looks like this:
+Example:
+https://api.twitter.com/1.1/lists/members.json
+Returns the members of the specified list. Private list members will only be shown if the authenticated user owns the specified list.
+The name of the company name followed by version followed by the purpose of the API.
+The methods:
+HTTP methods & URLs
+
+The API uses the following HTTP methods for object manipulation:
+
+```sh
+GET Used for object retrieval
+POST Used for object creation and object actions
+PUT Used for object update
+DELETE Used for object deletion
+```
+
+Let us build an API which collects information about 30DaysOfPython students. We will collect the name, country, city, date of birth, skills and bio.
+
+To implement this API, we will use:
+
+- Postman
+- Python
+- Flask
+- MongoDB
+
+### Retrieving data using get
+
+In this step, let us use dummy data and return it as a json. To return it as json, will use json module and Response module.
+
+```py
+# let's import the flask
+
+from flask import Flask, Response
+import json
+
+app = Flask(__name__)
+
+@app.route('/api/v1.0/students', methods = ['GET'])
+def students ():
+ student_list = [
+ {
+ 'name':'Asabeneh',
+ 'country':'Finland',
+ 'city':'Helsinki',
+ 'skills':['HTML', 'CSS','JavaScript','Python']
+ },
+ {
+ 'name':'David',
+ 'country':'UK',
+ 'city':'London',
+ 'skills':['Python','MongoDB']
+ },
+ {
+ 'name':'John',
+ 'country':'Sweden',
+ 'city':'Stockholm',
+ 'skills':['Java','C#']
+ }
+ ]
+ return Response(json.dumps(student_list), mimetype='application/json')
+
+
+if __name__ == '__main__':
+ # for deployment
+ # to make it work for both production and development
+ port = int(os.environ.get("PORT", 5000))
+ app.run(debug=True, host='0.0.0.0', port=port)
+```
+
+When you request the http://localhost:5000/api/v1.0/students url on the browser you will get this:
+
+![Get on browser](../images/get_on_browser.png)
+
+When you request the http://localhost:5000/api/v1.0/students url on the browser you will get this:
+
+![Get on postman](../images/get_on_postman.png)
+
+In stead of displaying dummy data let us connect the flask application with MongoDB and get data from mongoDB database.
+
+```py
+# let's import the flask
+
+from flask import Flask, Response
+import json
+import pymongo
+
+
+app = Flask(__name__)
+
+#
+MONGODB_URI='mongodb+srv://asabeneh:your_password@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client = pymongo.MongoClient(MONGODB_URI)
+db = client['thirty_days_of_python'] # accessing the database
+
+@app.route('/api/v1.0/students', methods = ['GET'])
+def students ():
+
+ return Response(json.dumps(student), mimetype='application/json')
+
+
+if __name__ == '__main__':
+ # for deployment
+ # to make it work for both production and development
+ port = int(os.environ.get("PORT", 5000))
+ app.run(debug=True, host='0.0.0.0', port=port)
+```
+
+By connecting the flask, we can fetch students collection data from the thirty_days_of_python database.
+
+```sh
+[
+ {
+ "_id": {
+ "$oid": "5df68a21f106fe2d315bbc8b"
+ },
+ "name": "Asabeneh",
+ "country": "Finland",
+ "city": "Helsinki",
+ "age": 38
+ },
+ {
+ "_id": {
+ "$oid": "5df68a23f106fe2d315bbc8c"
+ },
+ "name": "David",
+ "country": "UK",
+ "city": "London",
+ "age": 34
+ },
+ {
+ "_id": {
+ "$oid": "5df68a23f106fe2d315bbc8e"
+ },
+ "name": "Sami",
+ "country": "Finland",
+ "city": "Helsinki",
+ "age": 25
+ }
+]
+```
+
+### Getting a document by id
+
+We can access signle document using an id, let's access Asabeneh using his id.
+http://localhost:5000/api/v1.0/students/5df68a21f106fe2d315bbc8b
+
+```py
+# let's import the flask
+
+from flask import Flask, Response
+import json
+from bson.objectid import ObjectId
+import json
+from bson.json_util import dumps
+import pymongo
+
+
+app = Flask(__name__)
+
+#
+MONGODB_URI='mongodb+srv://asabeneh:your_password@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client = pymongo.MongoClient(MONGODB_URI)
+db = client['thirty_days_of_python'] # accessing the database
+
+@app.route('/api/v1.0/students', methods = ['GET'])
+def students ():
+
+ return Response(json.dumps(student), mimetype='application/json')
+@app.route('/api/v1.0/students/', methods = ['GET'])
+def single_student (id):
+ student = db.students.find({'_id':ObjectId(id)})
+ return Response(dumps(student), mimetype='application/json')
+
+if __name__ == '__main__':
+ # for deployment
+ # to make it work for both production and development
+ port = int(os.environ.get("PORT", 5000))
+ app.run(debug=True, host='0.0.0.0', port=port)
+```
+
+```sh
+[
+ {
+ "_id": {
+ "$oid": "5df68a21f106fe2d315bbc8b"
+ },
+ "name": "Asabeneh",
+ "country": "Finland",
+ "city": "Helsinki",
+ "age": 38
+ }
+]
+```
+
+### Creating data using POST
+
+We use the POST request method to create data
+
+```py
+# let's import the flask
+
+from flask import Flask, Response
+import json
+from bson.objectid import ObjectId
+import json
+from bson.json_util import dumps
+import pymongo
+from datetime import datetime
+
+
+app = Flask(__name__)
+
+#
+MONGODB_URI='mongodb+srv://asabeneh:your_password@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client = pymongo.MongoClient(MONGODB_URI)
+db = client['thirty_days_of_python'] # accessing the database
+
+@app.route('/api/v1.0/students', methods = ['GET'])
+def students ():
+
+ return Response(json.dumps(student), mimetype='application/json')
+@app.route('/api/v1.0/students/', methods = ['GET'])
+def single_student (id):
+ student = db.students.find({'_id':ObjectId(id)})
+ return Response(dumps(student), mimetype='application/json')
+@app.route('/api/v1.0/students', methods = ['POST'])
+def create_student ():
+ name = request.form['name']
+ country = request.form['country']
+ city = request.form['city']
+ skills = request.form['skills'].split(', ')
+ bio = request.form['bio']
+ birthyear = request.form['birthyear']
+ created_at = datetime.now()
+ student = {
+ 'name': name,
+ 'country': country,
+ 'city': city,
+ 'birthyear': birthyear,
+ 'skills': skills,
+ 'bio': bio,
+ 'created_at': created_at
+
+ }
+ db.students.insert_one(student)
+ return ;
+def update_student (id):
+if __name__ == '__main__':
+ # for deployment
+ # to make it work for both production and development
+ port = int(os.environ.get("PORT", 5000))
+ app.run(debug=True, host='0.0.0.0', port=port)
+```
+
+### Updating using PUT
+
+```py
+# let's import the flask
+
+from flask import Flask, Response
+import json
+from bson.objectid import ObjectId
+import json
+from bson.json_util import dumps
+import pymongo
+from datetime import datetime
+
+
+app = Flask(__name__)
+
+#
+MONGODB_URI='mongodb+srv://asabeneh:your_password@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client = pymongo.MongoClient(MONGODB_URI)
+db = client['thirty_days_of_python'] # accessing the database
+
+@app.route('/api/v1.0/students', methods = ['GET'])
+def students ():
+
+ return Response(json.dumps(student), mimetype='application/json')
+@app.route('/api/v1.0/students/', methods = ['GET'])
+def single_student (id):
+ student = db.students.find({'_id':ObjectId(id)})
+ return Response(dumps(student), mimetype='application/json')
+@app.route('/api/v1.0/students', methods = ['POST'])
+def create_student ():
+ name = request.form['name']
+ country = request.form['country']
+ city = request.form['city']
+ skills = request.form['skills'].split(', ')
+ bio = request.form['bio']
+ birthyear = request.form['birthyear']
+ created_at = datetime.now()
+ student = {
+ 'name': name,
+ 'country': country,
+ 'city': city,
+ 'birthyear': birthyear,
+ 'skills': skills,
+ 'bio': bio,
+ 'created_at': created_at
+
+ }
+ db.students.insert_one(student)
+ return
+@app.route('/api/v1.0/students/', methods = ['PUT']) # this decorator create the home route
+def update_student (id):
+ query = {"_id":ObjectId(id)}
+ name = request.form['name']
+ country = request.form['country']
+ city = request.form['city']
+ skills = request.form['skills'].split(', ')
+ bio = request.form['bio']
+ birthyear = request.form['birthyear']
+ created_at = datetime.now()
+ student = {
+ 'name': name,
+ 'country': country,
+ 'city': city,
+ 'birthyear': birthyear,
+ 'skills': skills,
+ 'bio': bio,
+ 'created_at': created_at
+
+ }
+ db.students.update_one(query, student)
+ # return Response(dumps({"result":"a new student has been created"}), mimetype='application/json')
+ return
+def update_student (id):
+if __name__ == '__main__':
+ # for deployment
+ # to make it work for both production and development
+ port = int(os.environ.get("PORT", 5000))
+ app.run(debug=True, host='0.0.0.0', port=port)
+```
+
+### Deleting a document using Delete
+
+```py
+# let's import the flask
+
+from flask import Flask, Response
+import json
+from bson.objectid import ObjectId
+import json
+from bson.json_util import dumps
+import pymongo
+from datetime import datetime
+
+
+app = Flask(__name__)
+
+#
+MONGODB_URI='mongodb+srv://asabeneh:your_password@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client = pymongo.MongoClient(MONGODB_URI)
+db = client['thirty_days_of_python'] # accessing the database
+
+@app.route('/api/v1.0/students', methods = ['GET'])
+def students ():
+
+ return Response(json.dumps(student), mimetype='application/json')
+@app.route('/api/v1.0/students/', methods = ['GET'])
+def single_student (id):
+ student = db.students.find({'_id':ObjectId(id)})
+ return Response(dumps(student), mimetype='application/json')
+@app.route('/api/v1.0/students', methods = ['POST'])
+def create_student ():
+ name = request.form['name']
+ country = request.form['country']
+ city = request.form['city']
+ skills = request.form['skills'].split(', ')
+ bio = request.form['bio']
+ birthyear = request.form['birthyear']
+ created_at = datetime.now()
+ student = {
+ 'name': name,
+ 'country': country,
+ 'city': city,
+ 'birthyear': birthyear,
+ 'skills': skills,
+ 'bio': bio,
+ 'created_at': created_at
+
+ }
+ db.students.insert_one(student)
+ return
+@app.route('/api/v1.0/students/', methods = ['PUT']) # this decorator create the home route
+def update_student (id):
+ query = {"_id":ObjectId(id)}
+ name = request.form['name']
+ country = request.form['country']
+ city = request.form['city']
+ skills = request.form['skills'].split(', ')
+ bio = request.form['bio']
+ birthyear = request.form['birthyear']
+ created_at = datetime.now()
+ student = {
+ 'name': name,
+ 'country': country,
+ 'city': city,
+ 'birthyear': birthyear,
+ 'skills': skills,
+ 'bio': bio,
+ 'created_at': created_at
+
+ }
+ db.students.update_one(query, student)
+ # return Response(dumps({"result":"a new student has been created"}), mimetype='application/json')
+ return
+@app.route('/api/v1.0/students/', methods = ['PUT']) # this decorator create the home route
+def update_student (id):
+ query = {"_id":ObjectId(id)}
+ name = request.form['name']
+ country = request.form['country']
+ city = request.form['city']
+ skills = request.form['skills'].split(', ')
+ bio = request.form['bio']
+ birthyear = request.form['birthyear']
+ created_at = datetime.now()
+ student = {
+ 'name': name,
+ 'country': country,
+ 'city': city,
+ 'birthyear': birthyear,
+ 'skills': skills,
+ 'bio': bio,
+ 'created_at': created_at
+
+ }
+ db.students.update_one(query, student)
+ # return Response(dumps({"result":"a new student has been created"}), mimetype='application/json')
+ return ;
+@app.route('/api/v1.0/students/', methods = ['DELETE'])
+def delete_student (id):
+ db.students.delete_one({"_id":ObjectId(id)})
+ return
+if __name__ == '__main__':
+ # for deployment
+ # to make it work for both production and development
+ port = int(os.environ.get("PORT", 5000))
+ app.run(debug=True, host='0.0.0.0', port=port)
+```
+
+## 💻 Exercises: Day 29
+
+1. Implement the above example and develop [this](https://thirtydayofpython-api.herokuapp.com/)
+
+🎉 CONGRATULATIONS ! 🎉
+
+[<< Day 28](../28_Day_API/28_API.md) | [Day 30 >>](../30_Day_Conclusions/30_conclusions.md)
diff --git a/29_building_API/index.html b/29_building_API/index.html
new file mode 100644
index 0000000..8a728d1
--- /dev/null
+++ b/29_building_API/index.html
@@ -0,0 +1,1759 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 29 building API - 30天入门Python全栈开发
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
In this section, we will cove a RESTful API that uses HTTP request methods to GET, PUT, POST and DELETE data.
+
RESTful API is an application program interface (API) that uses HTTP requests to GET, PUT, POST and DELETE data. In the previous sections, we have learned about python, flask and mongoDB. We will use the knowledge we acquire to develop a RESTful API using python flask and mongoDB. Every application which has CRUD(Create, Read, Update, Delete) operation has an API to create data, to get data, to update data or to delete data from database.
+
The browser can handle only get request. Therefore, we have to have a tool which can help us to handle all request methods(GET, POST, PUT, DELETE).
+
Examples of API
+
+
Countries API: https://restcountries.eu/rest/v2/all
Postman is a very popular tool when it comes to API development. So, if you like to do this section you need to download postman. An alternative of Postman is Insomnia.
An API end point is a URL which can help to retrieve, create, update or delete a resource. The structure looks like this:
+Example:
+https://api.twitter.com/1.1/lists/members.json
+Returns the members of the specified list. Private list members will only be shown if the authenticated user owns the specified list.
+The name of the company name followed by version followed by the purpose of the API.
+The methods:
+HTTP methods & URLs
+
The API uses the following HTTP methods for object manipulation:
In this step, let us use dummy data and return it as a json. To return it as json, will use json module and Response module.
+
# let's import the flask
+
+fromflaskimportFlask,Response
+importjson
+
+app=Flask(__name__)
+
+@app.route('/api/v1.0/students',methods=['GET'])
+defstudents():
+ student_list=[
+ {
+ 'name':'Asabeneh',
+ 'country':'Finland',
+ 'city':'Helsinki',
+ 'skills':['HTML','CSS','JavaScript','Python']
+ },
+ {
+ 'name':'David',
+ 'country':'UK',
+ 'city':'London',
+ 'skills':['Python','MongoDB']
+ },
+ {
+ 'name':'John',
+ 'country':'Sweden',
+ 'city':'Stockholm',
+ 'skills':['Java','C#']
+ }
+ ]
+ returnResponse(json.dumps(student_list),mimetype='application/json')
+
+
+if__name__=='__main__':
+ # for deployment
+ # to make it work for both production and development
+ port=int(os.environ.get("PORT",5000))
+ app.run(debug=True,host='0.0.0.0',port=port)
+
+
When you request the http://localhost:5000/api/v1.0/students url on the browser you will get this:
+
+
When you request the http://localhost:5000/api/v1.0/students url on the browser you will get this:
+
+
In stead of displaying dummy data let us connect the flask application with MongoDB and get data from mongoDB database.
+
# let's import the flask
+
+fromflaskimportFlask,Response
+importjson
+importpymongo
+
+
+app=Flask(__name__)
+
+#
+MONGODB_URI='mongodb+srv://asabeneh:your_password@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client=pymongo.MongoClient(MONGODB_URI)
+db=client['thirty_days_of_python']# accessing the database
+
+@app.route('/api/v1.0/students',methods=['GET'])
+defstudents():
+
+ returnResponse(json.dumps(student),mimetype='application/json')
+
+
+if__name__=='__main__':
+ # for deployment
+ # to make it work for both production and development
+ port=int(os.environ.get("PORT",5000))
+ app.run(debug=True,host='0.0.0.0',port=port)
+
+
By connecting the flask, we can fetch students collection data from the thirty_days_of_python database.
We can access signle document using an id, let's access Asabeneh using his id.
+http://localhost:5000/api/v1.0/students/5df68a21f106fe2d315bbc8b
+
# let's import the flask
+
+fromflaskimportFlask,Response
+importjson
+frombson.objectidimportObjectId
+importjson
+frombson.json_utilimportdumps
+importpymongo
+
+
+app=Flask(__name__)
+
+#
+MONGODB_URI='mongodb+srv://asabeneh:your_password@30daysofpython-twxkr.mongodb.net/test?retryWrites=true&w=majority'
+client=pymongo.MongoClient(MONGODB_URI)
+db=client['thirty_days_of_python']# accessing the database
+
+@app.route('/api/v1.0/students',methods=['GET'])
+defstudents():
+
+ returnResponse(json.dumps(student),mimetype='application/json')
+@app.route('/api/v1.0/students/<id>',methods=['GET'])
+defsingle_student(id):
+ student=db.students.find({'_id':ObjectId(id)})
+ returnResponse(dumps(student),mimetype='application/json')
+
+if__name__=='__main__':
+ # for deployment
+ # to make it work for both production and development
+ port=int(os.environ.get("PORT",5000))
+ app.run(debug=True,host='0.0.0.0',port=port)
+
+
+[<< Day 29](../29_Day_Building_API/29_building_API.md)
+![30DaysOfPython](../images/30DaysOfPython_banner3@2x.png)
+
+- [Day 30](#day-30)
+ - [Conclusions](#conclusions)
+
+# Day 30
+
+
+## Conclusions
+
+In the process of preparing this material I have learned quite a lot and you have inspired me to do more. Congratulations for making it to this level. If you have done all the exercise and the projects, now you are capable to go to a data analysis, data science, machine learning or web development paths. [Support the author for more educational materials](https://www.paypal.com/paypalme/asabeneh).
+
+## Testimony
+Now it is time to express your thoughts about the Author and 30DaysOfPyhton. You can leave your testimonial on this [link](https://testimonial-vdzd.onrender.com/)
+
+GIVE FEEDBACK:
+http://thirtydayofpython-api.herokuapp.com/feedback
+
+🎉 CONGRATULATIONS ! 🎉
+
+[<< Day 29](../29_Day_Building_API/29_building_API.md)
diff --git a/30_conclusions/index.html b/30_conclusions/index.html
new file mode 100644
index 0000000..e74b8a0
--- /dev/null
+++ b/30_conclusions/index.html
@@ -0,0 +1,1186 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 30 conclusions - 30天入门Python全栈开发
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
In the process of preparing this material I have learned quite a lot and you have inspired me to do more. Congratulations for making it to this level. If you have done all the exercise and the projects, now you are capable to go to a data analysis, data science, machine learning or web development paths. Support the author for more educational materials.
{"use strict";/*!
+ * escape-html
+ * Copyright(c) 2012-2013 TJ Holowaychuk
+ * Copyright(c) 2015 Andreas Lubbe
+ * Copyright(c) 2015 Tiancheng "Timothy" Gu
+ * MIT Licensed
+ */var Wa=/["'&<>]/;Vn.exports=Ua;function Ua(e){var t=""+e,r=Wa.exec(t);if(!r)return t;var o,n="",i=0,s=0;for(i=r.index;i0&&i[i.length-1])&&(p[0]===6||p[0]===2)){r=0;continue}if(p[0]===3&&(!i||p[1]>i[0]&&p[1]=e.length&&(e=void 0),{value:e&&e[o++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function z(e,t){var r=typeof Symbol=="function"&&e[Symbol.iterator];if(!r)return e;var o=r.call(e),n,i=[],s;try{for(;(t===void 0||t-- >0)&&!(n=o.next()).done;)i.push(n.value)}catch(a){s={error:a}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(s)throw s.error}}return i}function K(e,t,r){if(r||arguments.length===2)for(var o=0,n=t.length,i;o1||a(u,d)})})}function a(u,d){try{c(o[u](d))}catch(y){f(i[0][3],y)}}function c(u){u.value instanceof ot?Promise.resolve(u.value.v).then(p,l):f(i[0][2],u)}function p(u){a("next",u)}function l(u){a("throw",u)}function f(u,d){u(d),i.shift(),i.length&&a(i[0][0],i[0][1])}}function po(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],r;return t?t.call(e):(e=typeof be=="function"?be(e):e[Symbol.iterator](),r={},o("next"),o("throw"),o("return"),r[Symbol.asyncIterator]=function(){return this},r);function o(i){r[i]=e[i]&&function(s){return new Promise(function(a,c){s=e[i](s),n(a,c,s.done,s.value)})}}function n(i,s,a,c){Promise.resolve(c).then(function(p){i({value:p,done:a})},s)}}function k(e){return typeof e=="function"}function pt(e){var t=function(o){Error.call(o),o.stack=new Error().stack},r=e(t);return r.prototype=Object.create(Error.prototype),r.prototype.constructor=r,r}var Ut=pt(function(e){return function(r){e(this),this.message=r?r.length+` errors occurred during unsubscription:
+`+r.map(function(o,n){return n+1+") "+o.toString()}).join(`
+ `):"",this.name="UnsubscriptionError",this.errors=r}});function ze(e,t){if(e){var r=e.indexOf(t);0<=r&&e.splice(r,1)}}var je=function(){function e(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var t,r,o,n,i;if(!this.closed){this.closed=!0;var s=this._parentage;if(s)if(this._parentage=null,Array.isArray(s))try{for(var a=be(s),c=a.next();!c.done;c=a.next()){var p=c.value;p.remove(this)}}catch(b){t={error:b}}finally{try{c&&!c.done&&(r=a.return)&&r.call(a)}finally{if(t)throw t.error}}else s.remove(this);var l=this.initialTeardown;if(k(l))try{l()}catch(b){i=b instanceof Ut?b.errors:[b]}var f=this._finalizers;if(f){this._finalizers=null;try{for(var u=be(f),d=u.next();!d.done;d=u.next()){var y=d.value;try{lo(y)}catch(b){i=i!=null?i:[],b instanceof Ut?i=K(K([],z(i)),z(b.errors)):i.push(b)}}}catch(b){o={error:b}}finally{try{d&&!d.done&&(n=u.return)&&n.call(u)}finally{if(o)throw o.error}}}if(i)throw new Ut(i)}},e.prototype.add=function(t){var r;if(t&&t!==this)if(this.closed)lo(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(r=this._finalizers)!==null&&r!==void 0?r:[]).push(t)}},e.prototype._hasParent=function(t){var r=this._parentage;return r===t||Array.isArray(r)&&r.includes(t)},e.prototype._addParent=function(t){var r=this._parentage;this._parentage=Array.isArray(r)?(r.push(t),r):r?[r,t]:t},e.prototype._removeParent=function(t){var r=this._parentage;r===t?this._parentage=null:Array.isArray(r)&&ze(r,t)},e.prototype.remove=function(t){var r=this._finalizers;r&&ze(r,t),t instanceof e&&t._removeParent(this)},e.EMPTY=function(){var t=new e;return t.closed=!0,t}(),e}();var Tr=je.EMPTY;function Nt(e){return e instanceof je||e&&"closed"in e&&k(e.remove)&&k(e.add)&&k(e.unsubscribe)}function lo(e){k(e)?e():e.unsubscribe()}var He={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1};var lt={setTimeout:function(e,t){for(var r=[],o=2;o0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(r){return this._throwIfClosed(),e.prototype._trySubscribe.call(this,r)},t.prototype._subscribe=function(r){return this._throwIfClosed(),this._checkFinalizedStatuses(r),this._innerSubscribe(r)},t.prototype._innerSubscribe=function(r){var o=this,n=this,i=n.hasError,s=n.isStopped,a=n.observers;return i||s?Tr:(this.currentObservers=null,a.push(r),new je(function(){o.currentObservers=null,ze(a,r)}))},t.prototype._checkFinalizedStatuses=function(r){var o=this,n=o.hasError,i=o.thrownError,s=o.isStopped;n?r.error(i):s&&r.complete()},t.prototype.asObservable=function(){var r=new I;return r.source=this,r},t.create=function(r,o){return new xo(r,o)},t}(I);var xo=function(e){se(t,e);function t(r,o){var n=e.call(this)||this;return n.destination=r,n.source=o,n}return t.prototype.next=function(r){var o,n;(n=(o=this.destination)===null||o===void 0?void 0:o.next)===null||n===void 0||n.call(o,r)},t.prototype.error=function(r){var o,n;(n=(o=this.destination)===null||o===void 0?void 0:o.error)===null||n===void 0||n.call(o,r)},t.prototype.complete=function(){var r,o;(o=(r=this.destination)===null||r===void 0?void 0:r.complete)===null||o===void 0||o.call(r)},t.prototype._subscribe=function(r){var o,n;return(n=(o=this.source)===null||o===void 0?void 0:o.subscribe(r))!==null&&n!==void 0?n:Tr},t}(x);var St={now:function(){return(St.delegate||Date).now()},delegate:void 0};var Ot=function(e){se(t,e);function t(r,o,n){r===void 0&&(r=1/0),o===void 0&&(o=1/0),n===void 0&&(n=St);var i=e.call(this)||this;return i._bufferSize=r,i._windowTime=o,i._timestampProvider=n,i._buffer=[],i._infiniteTimeWindow=!0,i._infiniteTimeWindow=o===1/0,i._bufferSize=Math.max(1,r),i._windowTime=Math.max(1,o),i}return t.prototype.next=function(r){var o=this,n=o.isStopped,i=o._buffer,s=o._infiniteTimeWindow,a=o._timestampProvider,c=o._windowTime;n||(i.push(r),!s&&i.push(a.now()+c)),this._trimBuffer(),e.prototype.next.call(this,r)},t.prototype._subscribe=function(r){this._throwIfClosed(),this._trimBuffer();for(var o=this._innerSubscribe(r),n=this,i=n._infiniteTimeWindow,s=n._buffer,a=s.slice(),c=0;c0?e.prototype.requestAsyncId.call(this,r,o,n):(r.actions.push(this),r._scheduled||(r._scheduled=ut.requestAnimationFrame(function(){return r.flush(void 0)})))},t.prototype.recycleAsyncId=function(r,o,n){var i;if(n===void 0&&(n=0),n!=null?n>0:this.delay>0)return e.prototype.recycleAsyncId.call(this,r,o,n);var s=r.actions;o!=null&&((i=s[s.length-1])===null||i===void 0?void 0:i.id)!==o&&(ut.cancelAnimationFrame(o),r._scheduled=void 0)},t}(zt);var wo=function(e){se(t,e);function t(){return e!==null&&e.apply(this,arguments)||this}return t.prototype.flush=function(r){this._active=!0;var o=this._scheduled;this._scheduled=void 0;var n=this.actions,i;r=r||n.shift();do if(i=r.execute(r.state,r.delay))break;while((r=n[0])&&r.id===o&&n.shift());if(this._active=!1,i){for(;(r=n[0])&&r.id===o&&n.shift();)r.unsubscribe();throw i}},t}(qt);var ge=new wo(Eo);var M=new I(function(e){return e.complete()});function Kt(e){return e&&k(e.schedule)}function Cr(e){return e[e.length-1]}function Ge(e){return k(Cr(e))?e.pop():void 0}function Ae(e){return Kt(Cr(e))?e.pop():void 0}function Qt(e,t){return typeof Cr(e)=="number"?e.pop():t}var dt=function(e){return e&&typeof e.length=="number"&&typeof e!="function"};function Yt(e){return k(e==null?void 0:e.then)}function Bt(e){return k(e[ft])}function Gt(e){return Symbol.asyncIterator&&k(e==null?void 0:e[Symbol.asyncIterator])}function Jt(e){return new TypeError("You provided "+(e!==null&&typeof e=="object"?"an invalid object":"'"+e+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}function Wi(){return typeof Symbol!="function"||!Symbol.iterator?"@@iterator":Symbol.iterator}var Xt=Wi();function Zt(e){return k(e==null?void 0:e[Xt])}function er(e){return co(this,arguments,function(){var r,o,n,i;return Wt(this,function(s){switch(s.label){case 0:r=e.getReader(),s.label=1;case 1:s.trys.push([1,,9,10]),s.label=2;case 2:return[4,ot(r.read())];case 3:return o=s.sent(),n=o.value,i=o.done,i?[4,ot(void 0)]:[3,5];case 4:return[2,s.sent()];case 5:return[4,ot(n)];case 6:return[4,s.sent()];case 7:return s.sent(),[3,2];case 8:return[3,10];case 9:return r.releaseLock(),[7];case 10:return[2]}})})}function tr(e){return k(e==null?void 0:e.getReader)}function F(e){if(e instanceof I)return e;if(e!=null){if(Bt(e))return Ui(e);if(dt(e))return Ni(e);if(Yt(e))return Di(e);if(Gt(e))return To(e);if(Zt(e))return Vi(e);if(tr(e))return zi(e)}throw Jt(e)}function Ui(e){return new I(function(t){var r=e[ft]();if(k(r.subscribe))return r.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")})}function Ni(e){return new I(function(t){for(var r=0;r=2;return function(o){return o.pipe(e?v(function(n,i){return e(n,i,o)}):pe,ue(1),r?$e(t):Uo(function(){return new or}))}}function Rr(e){return e<=0?function(){return M}:g(function(t,r){var o=[];t.subscribe(E(r,function(n){o.push(n),e=2,!0))}function de(e){e===void 0&&(e={});var t=e.connector,r=t===void 0?function(){return new x}:t,o=e.resetOnError,n=o===void 0?!0:o,i=e.resetOnComplete,s=i===void 0?!0:i,a=e.resetOnRefCountZero,c=a===void 0?!0:a;return function(p){var l,f,u,d=0,y=!1,b=!1,D=function(){f==null||f.unsubscribe(),f=void 0},Q=function(){D(),l=u=void 0,y=b=!1},J=function(){var C=l;Q(),C==null||C.unsubscribe()};return g(function(C,ct){d++,!b&&!y&&D();var Ve=u=u!=null?u:r();ct.add(function(){d--,d===0&&!b&&!y&&(f=jr(J,c))}),Ve.subscribe(ct),!l&&d>0&&(l=new it({next:function(Fe){return Ve.next(Fe)},error:function(Fe){b=!0,D(),f=jr(Q,n,Fe),Ve.error(Fe)},complete:function(){y=!0,D(),f=jr(Q,s),Ve.complete()}}),F(C).subscribe(l))})(p)}}function jr(e,t){for(var r=[],o=2;oe.next(document)),e}function W(e,t=document){return Array.from(t.querySelectorAll(e))}function U(e,t=document){let r=ce(e,t);if(typeof r=="undefined")throw new ReferenceError(`Missing element: expected "${e}" to be present`);return r}function ce(e,t=document){return t.querySelector(e)||void 0}function Ie(){return document.activeElement instanceof HTMLElement&&document.activeElement||void 0}var ca=L(h(document.body,"focusin"),h(document.body,"focusout")).pipe(ye(1),q(void 0),m(()=>Ie()||document.body),Z(1));function vt(e){return ca.pipe(m(t=>e.contains(t)),X())}function qo(e,t){return L(h(e,"mouseenter").pipe(m(()=>!0)),h(e,"mouseleave").pipe(m(()=>!1))).pipe(t?ye(t):pe,q(!1))}function Ue(e){return{x:e.offsetLeft,y:e.offsetTop}}function Ko(e){return L(h(window,"load"),h(window,"resize")).pipe(Le(0,ge),m(()=>Ue(e)),q(Ue(e)))}function ir(e){return{x:e.scrollLeft,y:e.scrollTop}}function et(e){return L(h(e,"scroll"),h(window,"resize")).pipe(Le(0,ge),m(()=>ir(e)),q(ir(e)))}function Qo(e,t){if(typeof t=="string"||typeof t=="number")e.innerHTML+=t.toString();else if(t instanceof Node)e.appendChild(t);else if(Array.isArray(t))for(let r of t)Qo(e,r)}function S(e,t,...r){let o=document.createElement(e);if(t)for(let n of Object.keys(t))typeof t[n]!="undefined"&&(typeof t[n]!="boolean"?o.setAttribute(n,t[n]):o.setAttribute(n,""));for(let n of r)Qo(o,n);return o}function ar(e){if(e>999){let t=+((e-950)%1e3>99);return`${((e+1e-6)/1e3).toFixed(t)}k`}else return e.toString()}function gt(e){let t=S("script",{src:e});return H(()=>(document.head.appendChild(t),L(h(t,"load"),h(t,"error").pipe(w(()=>kr(()=>new ReferenceError(`Invalid script: ${e}`))))).pipe(m(()=>{}),A(()=>document.head.removeChild(t)),ue(1))))}var Yo=new x,pa=H(()=>typeof ResizeObserver=="undefined"?gt("https://unpkg.com/resize-observer-polyfill"):R(void 0)).pipe(m(()=>new ResizeObserver(e=>{for(let t of e)Yo.next(t)})),w(e=>L(Ke,R(e)).pipe(A(()=>e.disconnect()))),Z(1));function le(e){return{width:e.offsetWidth,height:e.offsetHeight}}function Se(e){return pa.pipe(T(t=>t.observe(e)),w(t=>Yo.pipe(v(({target:r})=>r===e),A(()=>t.unobserve(e)),m(()=>le(e)))),q(le(e)))}function xt(e){return{width:e.scrollWidth,height:e.scrollHeight}}function sr(e){let t=e.parentElement;for(;t&&(e.scrollWidth<=t.scrollWidth&&e.scrollHeight<=t.scrollHeight);)t=(e=t).parentElement;return t?e:void 0}var Bo=new x,la=H(()=>R(new IntersectionObserver(e=>{for(let t of e)Bo.next(t)},{threshold:0}))).pipe(w(e=>L(Ke,R(e)).pipe(A(()=>e.disconnect()))),Z(1));function yt(e){return la.pipe(T(t=>t.observe(e)),w(t=>Bo.pipe(v(({target:r})=>r===e),A(()=>t.unobserve(e)),m(({isIntersecting:r})=>r))))}function Go(e,t=16){return et(e).pipe(m(({y:r})=>{let o=le(e),n=xt(e);return r>=n.height-o.height-t}),X())}var cr={drawer:U("[data-md-toggle=drawer]"),search:U("[data-md-toggle=search]")};function Jo(e){return cr[e].checked}function Ye(e,t){cr[e].checked!==t&&cr[e].click()}function Ne(e){let t=cr[e];return h(t,"change").pipe(m(()=>t.checked),q(t.checked))}function ma(e,t){switch(e.constructor){case HTMLInputElement:return e.type==="radio"?/^Arrow/.test(t):!0;case HTMLSelectElement:case HTMLTextAreaElement:return!0;default:return e.isContentEditable}}function fa(){return L(h(window,"compositionstart").pipe(m(()=>!0)),h(window,"compositionend").pipe(m(()=>!1))).pipe(q(!1))}function Xo(){let e=h(window,"keydown").pipe(v(t=>!(t.metaKey||t.ctrlKey)),m(t=>({mode:Jo("search")?"search":"global",type:t.key,claim(){t.preventDefault(),t.stopPropagation()}})),v(({mode:t,type:r})=>{if(t==="global"){let o=Ie();if(typeof o!="undefined")return!ma(o,r)}return!0}),de());return fa().pipe(w(t=>t?M:e))}function me(){return new URL(location.href)}function st(e,t=!1){if(G("navigation.instant")&&!t){let r=S("a",{href:e.href});document.body.appendChild(r),r.click(),r.remove()}else location.href=e.href}function Zo(){return new x}function en(){return location.hash.slice(1)}function pr(e){let t=S("a",{href:e});t.addEventListener("click",r=>r.stopPropagation()),t.click()}function ua(e){return L(h(window,"hashchange"),e).pipe(m(en),q(en()),v(t=>t.length>0),Z(1))}function tn(e){return ua(e).pipe(m(t=>ce(`[id="${t}"]`)),v(t=>typeof t!="undefined"))}function At(e){let t=matchMedia(e);return nr(r=>t.addListener(()=>r(t.matches))).pipe(q(t.matches))}function rn(){let e=matchMedia("print");return L(h(window,"beforeprint").pipe(m(()=>!0)),h(window,"afterprint").pipe(m(()=>!1))).pipe(q(e.matches))}function Dr(e,t){return e.pipe(w(r=>r?t():M))}function lr(e,t){return new I(r=>{let o=new XMLHttpRequest;o.open("GET",`${e}`),o.responseType="blob",o.addEventListener("load",()=>{o.status>=200&&o.status<300?(r.next(o.response),r.complete()):r.error(new Error(o.statusText))}),o.addEventListener("error",()=>{r.error(new Error("Network Error"))}),o.addEventListener("abort",()=>{r.error(new Error("Request aborted"))}),typeof(t==null?void 0:t.progress$)!="undefined"&&(o.addEventListener("progress",n=>{if(n.lengthComputable)t.progress$.next(n.loaded/n.total*100);else{let i=Number(o.getResponseHeader("Content-Length"))||0;t.progress$.next(n.loaded/i*100)}}),t.progress$.next(5)),o.send()})}function De(e,t){return lr(e,t).pipe(w(r=>r.text()),m(r=>JSON.parse(r)),Z(1))}function on(e,t){let r=new DOMParser;return lr(e,t).pipe(w(o=>o.text()),m(o=>r.parseFromString(o,"text/xml")),Z(1))}function nn(){return{x:Math.max(0,scrollX),y:Math.max(0,scrollY)}}function an(){return L(h(window,"scroll",{passive:!0}),h(window,"resize",{passive:!0})).pipe(m(nn),q(nn()))}function sn(){return{width:innerWidth,height:innerHeight}}function cn(){return h(window,"resize",{passive:!0}).pipe(m(sn),q(sn()))}function pn(){return B([an(),cn()]).pipe(m(([e,t])=>({offset:e,size:t})),Z(1))}function mr(e,{viewport$:t,header$:r}){let o=t.pipe(te("size")),n=B([o,r]).pipe(m(()=>Ue(e)));return B([r,t,n]).pipe(m(([{height:i},{offset:s,size:a},{x:c,y:p}])=>({offset:{x:s.x-c,y:s.y-p+i},size:a})))}function da(e){return h(e,"message",t=>t.data)}function ha(e){let t=new x;return t.subscribe(r=>e.postMessage(r)),t}function ln(e,t=new Worker(e)){let r=da(t),o=ha(t),n=new x;n.subscribe(o);let i=o.pipe(ee(),oe(!0));return n.pipe(ee(),Re(r.pipe(j(i))),de())}var ba=U("#__config"),Et=JSON.parse(ba.textContent);Et.base=`${new URL(Et.base,me())}`;function he(){return Et}function G(e){return Et.features.includes(e)}function we(e,t){return typeof t!="undefined"?Et.translations[e].replace("#",t.toString()):Et.translations[e]}function Oe(e,t=document){return U(`[data-md-component=${e}]`,t)}function ne(e,t=document){return W(`[data-md-component=${e}]`,t)}function va(e){let t=U(".md-typeset > :first-child",e);return h(t,"click",{once:!0}).pipe(m(()=>U(".md-typeset",e)),m(r=>({hash:__md_hash(r.innerHTML)})))}function mn(e){if(!G("announce.dismiss")||!e.childElementCount)return M;if(!e.hidden){let t=U(".md-typeset",e);__md_hash(t.innerHTML)===__md_get("__announce")&&(e.hidden=!0)}return H(()=>{let t=new x;return t.subscribe(({hash:r})=>{e.hidden=!0,__md_set("__announce",r)}),va(e).pipe(T(r=>t.next(r)),A(()=>t.complete()),m(r=>P({ref:e},r)))})}function ga(e,{target$:t}){return t.pipe(m(r=>({hidden:r!==e})))}function fn(e,t){let r=new x;return r.subscribe(({hidden:o})=>{e.hidden=o}),ga(e,t).pipe(T(o=>r.next(o)),A(()=>r.complete()),m(o=>P({ref:e},o)))}function Ct(e,t){return t==="inline"?S("div",{class:"md-tooltip md-tooltip--inline",id:e,role:"tooltip"},S("div",{class:"md-tooltip__inner md-typeset"})):S("div",{class:"md-tooltip",id:e,role:"tooltip"},S("div",{class:"md-tooltip__inner md-typeset"}))}function un(e,t){if(t=t?`${t}_annotation_${e}`:void 0,t){let r=t?`#${t}`:void 0;return S("aside",{class:"md-annotation",tabIndex:0},Ct(t),S("a",{href:r,class:"md-annotation__index",tabIndex:-1},S("span",{"data-md-annotation-id":e})))}else return S("aside",{class:"md-annotation",tabIndex:0},Ct(t),S("span",{class:"md-annotation__index",tabIndex:-1},S("span",{"data-md-annotation-id":e})))}function dn(e){return S("button",{class:"md-clipboard md-icon",title:we("clipboard.copy"),"data-clipboard-target":`#${e} > code`})}function Vr(e,t){let r=t&2,o=t&1,n=Object.keys(e.terms).filter(c=>!e.terms[c]).reduce((c,p)=>[...c,S("del",null,p)," "],[]).slice(0,-1),i=he(),s=new URL(e.location,i.base);G("search.highlight")&&s.searchParams.set("h",Object.entries(e.terms).filter(([,c])=>c).reduce((c,[p])=>`${c} ${p}`.trim(),""));let{tags:a}=he();return S("a",{href:`${s}`,class:"md-search-result__link",tabIndex:-1},S("article",{class:"md-search-result__article md-typeset","data-md-score":e.score.toFixed(2)},r>0&&S("div",{class:"md-search-result__icon md-icon"}),r>0&&S("h1",null,e.title),r<=0&&S("h2",null,e.title),o>0&&e.text.length>0&&e.text,e.tags&&e.tags.map(c=>{let p=a?c in a?`md-tag-icon md-tag--${a[c]}`:"md-tag-icon":"";return S("span",{class:`md-tag ${p}`},c)}),o>0&&n.length>0&&S("p",{class:"md-search-result__terms"},we("search.result.term.missing"),": ",...n)))}function hn(e){let t=e[0].score,r=[...e],o=he(),n=r.findIndex(l=>!`${new URL(l.location,o.base)}`.includes("#")),[i]=r.splice(n,1),s=r.findIndex(l=>l.scoreVr(l,1)),...c.length?[S("details",{class:"md-search-result__more"},S("summary",{tabIndex:-1},S("div",null,c.length>0&&c.length===1?we("search.result.more.one"):we("search.result.more.other",c.length))),...c.map(l=>Vr(l,1)))]:[]];return S("li",{class:"md-search-result__item"},p)}function bn(e){return S("ul",{class:"md-source__facts"},Object.entries(e).map(([t,r])=>S("li",{class:`md-source__fact md-source__fact--${t}`},typeof r=="number"?ar(r):r)))}function zr(e){let t=`tabbed-control tabbed-control--${e}`;return S("div",{class:t,hidden:!0},S("button",{class:"tabbed-button",tabIndex:-1,"aria-hidden":"true"}))}function vn(e){return S("div",{class:"md-typeset__scrollwrap"},S("div",{class:"md-typeset__table"},e))}function xa(e){let t=he(),r=new URL(`../${e.version}/`,t.base);return S("li",{class:"md-version__item"},S("a",{href:`${r}`,class:"md-version__link"},e.title))}function gn(e,t){return S("div",{class:"md-version"},S("button",{class:"md-version__current","aria-label":we("select.version")},t.title),S("ul",{class:"md-version__list"},e.map(xa)))}var ya=0;function Ea(e,t){document.body.append(e);let{width:r}=le(e);e.style.setProperty("--md-tooltip-width",`${r}px`),e.remove();let o=sr(t),n=typeof o!="undefined"?et(o):R({x:0,y:0}),i=L(vt(t),qo(t)).pipe(X());return B([i,n]).pipe(m(([s,a])=>{let{x:c,y:p}=Ue(t),l=le(t),f=t.closest("table");return f&&t.parentElement&&(c+=f.offsetLeft+t.parentElement.offsetLeft,p+=f.offsetTop+t.parentElement.offsetTop),{active:s,offset:{x:c-a.x+l.width/2-r/2,y:p-a.y+l.height+8}}}))}function Be(e){let t=e.title;if(!t.length)return M;let r=`__tooltip_${ya++}`,o=Ct(r,"inline"),n=U(".md-typeset",o);return n.innerHTML=t,H(()=>{let i=new x;return i.subscribe({next({offset:s}){o.style.setProperty("--md-tooltip-x",`${s.x}px`),o.style.setProperty("--md-tooltip-y",`${s.y}px`)},complete(){o.style.removeProperty("--md-tooltip-x"),o.style.removeProperty("--md-tooltip-y")}}),L(i.pipe(v(({active:s})=>s)),i.pipe(ye(250),v(({active:s})=>!s))).subscribe({next({active:s}){s?(e.insertAdjacentElement("afterend",o),e.setAttribute("aria-describedby",r),e.removeAttribute("title")):(o.remove(),e.removeAttribute("aria-describedby"),e.setAttribute("title",t))},complete(){o.remove(),e.removeAttribute("aria-describedby"),e.setAttribute("title",t)}}),i.pipe(Le(16,ge)).subscribe(({active:s})=>{o.classList.toggle("md-tooltip--active",s)}),i.pipe(_t(125,ge),v(()=>!!e.offsetParent),m(()=>e.offsetParent.getBoundingClientRect()),m(({x:s})=>s)).subscribe({next(s){s?o.style.setProperty("--md-tooltip-0",`${-s}px`):o.style.removeProperty("--md-tooltip-0")},complete(){o.style.removeProperty("--md-tooltip-0")}}),Ea(o,e).pipe(T(s=>i.next(s)),A(()=>i.complete()),m(s=>P({ref:e},s)))}).pipe(qe(ie))}function wa(e,t){let r=H(()=>B([Ko(e),et(t)])).pipe(m(([{x:o,y:n},i])=>{let{width:s,height:a}=le(e);return{x:o-i.x+s/2,y:n-i.y+a/2}}));return vt(e).pipe(w(o=>r.pipe(m(n=>({active:o,offset:n})),ue(+!o||1/0))))}function xn(e,t,{target$:r}){let[o,n]=Array.from(e.children);return H(()=>{let i=new x,s=i.pipe(ee(),oe(!0));return i.subscribe({next({offset:a}){e.style.setProperty("--md-tooltip-x",`${a.x}px`),e.style.setProperty("--md-tooltip-y",`${a.y}px`)},complete(){e.style.removeProperty("--md-tooltip-x"),e.style.removeProperty("--md-tooltip-y")}}),yt(e).pipe(j(s)).subscribe(a=>{e.toggleAttribute("data-md-visible",a)}),L(i.pipe(v(({active:a})=>a)),i.pipe(ye(250),v(({active:a})=>!a))).subscribe({next({active:a}){a?e.prepend(o):o.remove()},complete(){e.prepend(o)}}),i.pipe(Le(16,ge)).subscribe(({active:a})=>{o.classList.toggle("md-tooltip--active",a)}),i.pipe(_t(125,ge),v(()=>!!e.offsetParent),m(()=>e.offsetParent.getBoundingClientRect()),m(({x:a})=>a)).subscribe({next(a){a?e.style.setProperty("--md-tooltip-0",`${-a}px`):e.style.removeProperty("--md-tooltip-0")},complete(){e.style.removeProperty("--md-tooltip-0")}}),h(n,"click").pipe(j(s),v(a=>!(a.metaKey||a.ctrlKey))).subscribe(a=>{a.stopPropagation(),a.preventDefault()}),h(n,"mousedown").pipe(j(s),ae(i)).subscribe(([a,{active:c}])=>{var p;if(a.button!==0||a.metaKey||a.ctrlKey)a.preventDefault();else if(c){a.preventDefault();let l=e.parentElement.closest(".md-annotation");l instanceof HTMLElement?l.focus():(p=Ie())==null||p.blur()}}),r.pipe(j(s),v(a=>a===o),Qe(125)).subscribe(()=>e.focus()),wa(e,t).pipe(T(a=>i.next(a)),A(()=>i.complete()),m(a=>P({ref:e},a)))})}function Ta(e){return e.tagName==="CODE"?W(".c, .c1, .cm",e):[e]}function Sa(e){let t=[];for(let r of Ta(e)){let o=[],n=document.createNodeIterator(r,NodeFilter.SHOW_TEXT);for(let i=n.nextNode();i;i=n.nextNode())o.push(i);for(let i of o){let s;for(;s=/(\(\d+\))(!)?/.exec(i.textContent);){let[,a,c]=s;if(typeof c=="undefined"){let p=i.splitText(s.index);i=p.splitText(a.length),t.push(p)}else{i.textContent=a,t.push(i);break}}}}return t}function yn(e,t){t.append(...Array.from(e.childNodes))}function fr(e,t,{target$:r,print$:o}){let n=t.closest("[id]"),i=n==null?void 0:n.id,s=new Map;for(let a of Sa(t)){let[,c]=a.textContent.match(/\((\d+)\)/);ce(`:scope > li:nth-child(${c})`,e)&&(s.set(c,un(c,i)),a.replaceWith(s.get(c)))}return s.size===0?M:H(()=>{let a=new x,c=a.pipe(ee(),oe(!0)),p=[];for(let[l,f]of s)p.push([U(".md-typeset",f),U(`:scope > li:nth-child(${l})`,e)]);return o.pipe(j(c)).subscribe(l=>{e.hidden=!l,e.classList.toggle("md-annotation-list",l);for(let[f,u]of p)l?yn(f,u):yn(u,f)}),L(...[...s].map(([,l])=>xn(l,t,{target$:r}))).pipe(A(()=>a.complete()),de())})}function En(e){if(e.nextElementSibling){let t=e.nextElementSibling;if(t.tagName==="OL")return t;if(t.tagName==="P"&&!t.children.length)return En(t)}}function wn(e,t){return H(()=>{let r=En(e);return typeof r!="undefined"?fr(r,e,t):M})}var Tn=jt(Kr());var Oa=0;function Sn(e){if(e.nextElementSibling){let t=e.nextElementSibling;if(t.tagName==="OL")return t;if(t.tagName==="P"&&!t.children.length)return Sn(t)}}function Ma(e){return Se(e).pipe(m(({width:t})=>({scrollable:xt(e).width>t})),te("scrollable"))}function On(e,t){let{matches:r}=matchMedia("(hover)"),o=H(()=>{let n=new x,i=n.pipe(Rr(1));n.subscribe(({scrollable:c})=>{c&&r?e.setAttribute("tabindex","0"):e.removeAttribute("tabindex")});let s=[];if(Tn.default.isSupported()&&(e.closest(".copy")||G("content.code.copy")&&!e.closest(".no-copy"))){let c=e.closest("pre");c.id=`__code_${Oa++}`;let p=dn(c.id);c.insertBefore(p,e),G("content.tooltips")&&s.push(Be(p))}let a=e.closest(".highlight");if(a instanceof HTMLElement){let c=Sn(a);if(typeof c!="undefined"&&(a.classList.contains("annotate")||G("content.code.annotate"))){let p=fr(c,e,t);s.push(Se(a).pipe(j(i),m(({width:l,height:f})=>l&&f),X(),w(l=>l?p:M)))}}return Ma(e).pipe(T(c=>n.next(c)),A(()=>n.complete()),m(c=>P({ref:e},c)),Re(...s))});return G("content.lazy")?yt(e).pipe(v(n=>n),ue(1),w(()=>o)):o}function La(e,{target$:t,print$:r}){let o=!0;return L(t.pipe(m(n=>n.closest("details:not([open])")),v(n=>e===n),m(()=>({action:"open",reveal:!0}))),r.pipe(v(n=>n||!o),T(()=>o=e.open),m(n=>({action:n?"open":"close"}))))}function Mn(e,t){return H(()=>{let r=new x;return r.subscribe(({action:o,reveal:n})=>{e.toggleAttribute("open",o==="open"),n&&e.scrollIntoView()}),La(e,t).pipe(T(o=>r.next(o)),A(()=>r.complete()),m(o=>P({ref:e},o)))})}var Ln=".node circle,.node ellipse,.node path,.node polygon,.node rect{fill:var(--md-mermaid-node-bg-color);stroke:var(--md-mermaid-node-fg-color)}marker{fill:var(--md-mermaid-edge-color)!important}.edgeLabel .label rect{fill:#0000}.label{color:var(--md-mermaid-label-fg-color);font-family:var(--md-mermaid-font-family)}.label foreignObject{line-height:normal;overflow:visible}.label div .edgeLabel{color:var(--md-mermaid-label-fg-color)}.edgeLabel,.edgeLabel rect,.label div .edgeLabel{background-color:var(--md-mermaid-label-bg-color)}.edgeLabel,.edgeLabel rect{fill:var(--md-mermaid-label-bg-color);color:var(--md-mermaid-edge-color)}.edgePath .path,.flowchart-link{stroke:var(--md-mermaid-edge-color);stroke-width:.05rem}.edgePath .arrowheadPath{fill:var(--md-mermaid-edge-color);stroke:none}.cluster rect{fill:var(--md-default-fg-color--lightest);stroke:var(--md-default-fg-color--lighter)}.cluster span{color:var(--md-mermaid-label-fg-color);font-family:var(--md-mermaid-font-family)}g #flowchart-circleEnd,g #flowchart-circleStart,g #flowchart-crossEnd,g #flowchart-crossStart,g #flowchart-pointEnd,g #flowchart-pointStart{stroke:none}g.classGroup line,g.classGroup rect{fill:var(--md-mermaid-node-bg-color);stroke:var(--md-mermaid-node-fg-color)}g.classGroup text{fill:var(--md-mermaid-label-fg-color);font-family:var(--md-mermaid-font-family)}.classLabel .box{fill:var(--md-mermaid-label-bg-color);background-color:var(--md-mermaid-label-bg-color);opacity:1}.classLabel .label{fill:var(--md-mermaid-label-fg-color);font-family:var(--md-mermaid-font-family)}.node .divider{stroke:var(--md-mermaid-node-fg-color)}.relation{stroke:var(--md-mermaid-edge-color)}.cardinality{fill:var(--md-mermaid-label-fg-color);font-family:var(--md-mermaid-font-family)}.cardinality text{fill:inherit!important}defs #classDiagram-compositionEnd,defs #classDiagram-compositionStart,defs #classDiagram-dependencyEnd,defs #classDiagram-dependencyStart,defs #classDiagram-extensionEnd,defs #classDiagram-extensionStart{fill:var(--md-mermaid-edge-color)!important;stroke:var(--md-mermaid-edge-color)!important}defs #classDiagram-aggregationEnd,defs #classDiagram-aggregationStart{fill:var(--md-mermaid-label-bg-color)!important;stroke:var(--md-mermaid-edge-color)!important}g.stateGroup rect{fill:var(--md-mermaid-node-bg-color);stroke:var(--md-mermaid-node-fg-color)}g.stateGroup .state-title{fill:var(--md-mermaid-label-fg-color)!important;font-family:var(--md-mermaid-font-family)}g.stateGroup .composit{fill:var(--md-mermaid-label-bg-color)}.nodeLabel{color:var(--md-mermaid-label-fg-color);font-family:var(--md-mermaid-font-family)}.node circle.state-end,.node circle.state-start,.start-state{fill:var(--md-mermaid-edge-color);stroke:none}.end-state-inner,.end-state-outer{fill:var(--md-mermaid-edge-color)}.end-state-inner,.node circle.state-end{stroke:var(--md-mermaid-label-bg-color)}.transition{stroke:var(--md-mermaid-edge-color)}[id^=state-fork] rect,[id^=state-join] rect{fill:var(--md-mermaid-edge-color)!important;stroke:none!important}.statediagram-cluster.statediagram-cluster .inner{fill:var(--md-default-bg-color)}.statediagram-cluster rect{fill:var(--md-mermaid-node-bg-color);stroke:var(--md-mermaid-node-fg-color)}.statediagram-state rect.divider{fill:var(--md-default-fg-color--lightest);stroke:var(--md-default-fg-color--lighter)}defs #statediagram-barbEnd{stroke:var(--md-mermaid-edge-color)}.attributeBoxEven,.attributeBoxOdd{fill:var(--md-mermaid-node-bg-color);stroke:var(--md-mermaid-node-fg-color)}.entityBox{fill:var(--md-mermaid-label-bg-color);stroke:var(--md-mermaid-node-fg-color)}.entityLabel{fill:var(--md-mermaid-label-fg-color);font-family:var(--md-mermaid-font-family)}.relationshipLabelBox{fill:var(--md-mermaid-label-bg-color);fill-opacity:1;background-color:var(--md-mermaid-label-bg-color);opacity:1}.relationshipLabel{fill:var(--md-mermaid-label-fg-color)}.relationshipLine{stroke:var(--md-mermaid-edge-color)}defs #ONE_OR_MORE_END *,defs #ONE_OR_MORE_START *,defs #ONLY_ONE_END *,defs #ONLY_ONE_START *,defs #ZERO_OR_MORE_END *,defs #ZERO_OR_MORE_START *,defs #ZERO_OR_ONE_END *,defs #ZERO_OR_ONE_START *{stroke:var(--md-mermaid-edge-color)!important}defs #ZERO_OR_MORE_END circle,defs #ZERO_OR_MORE_START circle{fill:var(--md-mermaid-label-bg-color)}.actor{fill:var(--md-mermaid-sequence-actor-bg-color);stroke:var(--md-mermaid-sequence-actor-border-color)}text.actor>tspan{fill:var(--md-mermaid-sequence-actor-fg-color);font-family:var(--md-mermaid-font-family)}line{stroke:var(--md-mermaid-sequence-actor-line-color)}.actor-man circle,.actor-man line{fill:var(--md-mermaid-sequence-actorman-bg-color);stroke:var(--md-mermaid-sequence-actorman-line-color)}.messageLine0,.messageLine1{stroke:var(--md-mermaid-sequence-message-line-color)}.note{fill:var(--md-mermaid-sequence-note-bg-color);stroke:var(--md-mermaid-sequence-note-border-color)}.loopText,.loopText>tspan,.messageText,.noteText>tspan{stroke:none;font-family:var(--md-mermaid-font-family)!important}.messageText{fill:var(--md-mermaid-sequence-message-fg-color)}.loopText,.loopText>tspan{fill:var(--md-mermaid-sequence-loop-fg-color)}.noteText>tspan{fill:var(--md-mermaid-sequence-note-fg-color)}#arrowhead path{fill:var(--md-mermaid-sequence-message-line-color);stroke:none}.loopLine{fill:var(--md-mermaid-sequence-loop-bg-color);stroke:var(--md-mermaid-sequence-loop-border-color)}.labelBox{fill:var(--md-mermaid-sequence-label-bg-color);stroke:none}.labelText,.labelText>span{fill:var(--md-mermaid-sequence-label-fg-color);font-family:var(--md-mermaid-font-family)}.sequenceNumber{fill:var(--md-mermaid-sequence-number-fg-color)}rect.rect{fill:var(--md-mermaid-sequence-box-bg-color);stroke:none}rect.rect+text.text{fill:var(--md-mermaid-sequence-box-fg-color)}defs #sequencenumber{fill:var(--md-mermaid-sequence-number-bg-color)!important}";var Qr,Aa=0;function Ca(){return typeof mermaid=="undefined"||mermaid instanceof Element?gt("https://unpkg.com/mermaid@10.6.1/dist/mermaid.min.js"):R(void 0)}function _n(e){return e.classList.remove("mermaid"),Qr||(Qr=Ca().pipe(T(()=>mermaid.initialize({startOnLoad:!1,themeCSS:Ln,sequence:{actorFontSize:"16px",messageFontSize:"16px",noteFontSize:"16px"}})),m(()=>{}),Z(1))),Qr.subscribe(()=>no(this,null,function*(){e.classList.add("mermaid");let t=`__mermaid_${Aa++}`,r=S("div",{class:"mermaid"}),o=e.textContent,{svg:n,fn:i}=yield mermaid.render(t,o),s=r.attachShadow({mode:"closed"});s.innerHTML=n,e.replaceWith(r),i==null||i(s)})),Qr.pipe(m(()=>({ref:e})))}var An=S("table");function Cn(e){return e.replaceWith(An),An.replaceWith(vn(e)),R({ref:e})}function ka(e){let t=e.find(r=>r.checked)||e[0];return L(...e.map(r=>h(r,"change").pipe(m(()=>U(`label[for="${r.id}"]`))))).pipe(q(U(`label[for="${t.id}"]`)),m(r=>({active:r})))}function kn(e,{viewport$:t,target$:r}){let o=U(".tabbed-labels",e),n=W(":scope > input",e),i=zr("prev");e.append(i);let s=zr("next");return e.append(s),H(()=>{let a=new x,c=a.pipe(ee(),oe(!0));B([a,Se(e)]).pipe(j(c),Le(1,ge)).subscribe({next([{active:p},l]){let f=Ue(p),{width:u}=le(p);e.style.setProperty("--md-indicator-x",`${f.x}px`),e.style.setProperty("--md-indicator-width",`${u}px`);let d=ir(o);(f.xd.x+l.width)&&o.scrollTo({left:Math.max(0,f.x-16),behavior:"smooth"})},complete(){e.style.removeProperty("--md-indicator-x"),e.style.removeProperty("--md-indicator-width")}}),B([et(o),Se(o)]).pipe(j(c)).subscribe(([p,l])=>{let f=xt(o);i.hidden=p.x<16,s.hidden=p.x>f.width-l.width-16}),L(h(i,"click").pipe(m(()=>-1)),h(s,"click").pipe(m(()=>1))).pipe(j(c)).subscribe(p=>{let{width:l}=le(o);o.scrollBy({left:l*p,behavior:"smooth"})}),r.pipe(j(c),v(p=>n.includes(p))).subscribe(p=>p.click()),o.classList.add("tabbed-labels--linked");for(let p of n){let l=U(`label[for="${p.id}"]`);l.replaceChildren(S("a",{href:`#${l.htmlFor}`,tabIndex:-1},...Array.from(l.childNodes))),h(l.firstElementChild,"click").pipe(j(c),v(f=>!(f.metaKey||f.ctrlKey)),T(f=>{f.preventDefault(),f.stopPropagation()})).subscribe(()=>{history.replaceState({},"",`#${l.htmlFor}`),l.click()})}return G("content.tabs.link")&&a.pipe(Ee(1),ae(t)).subscribe(([{active:p},{offset:l}])=>{let f=p.innerText.trim();if(p.hasAttribute("data-md-switching"))p.removeAttribute("data-md-switching");else{let u=e.offsetTop-l.y;for(let y of W("[data-tabs]"))for(let b of W(":scope > input",y)){let D=U(`label[for="${b.id}"]`);if(D!==p&&D.innerText.trim()===f){D.setAttribute("data-md-switching",""),b.click();break}}window.scrollTo({top:e.offsetTop-u});let d=__md_get("__tabs")||[];__md_set("__tabs",[...new Set([f,...d])])}}),a.pipe(j(c)).subscribe(()=>{for(let p of W("audio, video",e))p.pause()}),ka(n).pipe(T(p=>a.next(p)),A(()=>a.complete()),m(p=>P({ref:e},p)))}).pipe(qe(ie))}function Hn(e,{viewport$:t,target$:r,print$:o}){return L(...W(".annotate:not(.highlight)",e).map(n=>wn(n,{target$:r,print$:o})),...W("pre:not(.mermaid) > code",e).map(n=>On(n,{target$:r,print$:o})),...W("pre.mermaid",e).map(n=>_n(n)),...W("table:not([class])",e).map(n=>Cn(n)),...W("details",e).map(n=>Mn(n,{target$:r,print$:o})),...W("[data-tabs]",e).map(n=>kn(n,{viewport$:t,target$:r})),...W("[title]",e).filter(()=>G("content.tooltips")).map(n=>Be(n)))}function Ha(e,{alert$:t}){return t.pipe(w(r=>L(R(!0),R(!1).pipe(Qe(2e3))).pipe(m(o=>({message:r,active:o})))))}function $n(e,t){let r=U(".md-typeset",e);return H(()=>{let o=new x;return o.subscribe(({message:n,active:i})=>{e.classList.toggle("md-dialog--active",i),r.textContent=n}),Ha(e,t).pipe(T(n=>o.next(n)),A(()=>o.complete()),m(n=>P({ref:e},n)))})}function $a({viewport$:e}){if(!G("header.autohide"))return R(!1);let t=e.pipe(m(({offset:{y:n}})=>n),Ce(2,1),m(([n,i])=>[nMath.abs(i-n.y)>100),m(([,[n]])=>n),X()),o=Ne("search");return B([e,o]).pipe(m(([{offset:n},i])=>n.y>400&&!i),X(),w(n=>n?r:R(!1)),q(!1))}function Pn(e,t){return H(()=>B([Se(e),$a(t)])).pipe(m(([{height:r},o])=>({height:r,hidden:o})),X((r,o)=>r.height===o.height&&r.hidden===o.hidden),Z(1))}function Rn(e,{header$:t,main$:r}){return H(()=>{let o=new x,n=o.pipe(ee(),oe(!0));o.pipe(te("active"),Ze(t)).subscribe(([{active:s},{hidden:a}])=>{e.classList.toggle("md-header--shadow",s&&!a),e.hidden=a});let i=fe(W("[title]",e)).pipe(v(()=>G("content.tooltips")),re(s=>Be(s)));return r.subscribe(o),t.pipe(j(n),m(s=>P({ref:e},s)),Re(i.pipe(j(n))))})}function Pa(e,{viewport$:t,header$:r}){return mr(e,{viewport$:t,header$:r}).pipe(m(({offset:{y:o}})=>{let{height:n}=le(e);return{active:o>=n}}),te("active"))}function In(e,t){return H(()=>{let r=new x;r.subscribe({next({active:n}){e.classList.toggle("md-header__title--active",n)},complete(){e.classList.remove("md-header__title--active")}});let o=ce(".md-content h1");return typeof o=="undefined"?M:Pa(o,t).pipe(T(n=>r.next(n)),A(()=>r.complete()),m(n=>P({ref:e},n)))})}function Fn(e,{viewport$:t,header$:r}){let o=r.pipe(m(({height:i})=>i),X()),n=o.pipe(w(()=>Se(e).pipe(m(({height:i})=>({top:e.offsetTop,bottom:e.offsetTop+i})),te("bottom"))));return B([o,n,t]).pipe(m(([i,{top:s,bottom:a},{offset:{y:c},size:{height:p}}])=>(p=Math.max(0,p-Math.max(0,s-c,i)-Math.max(0,p+c-a)),{offset:s-i,height:p,active:s-i<=c})),X((i,s)=>i.offset===s.offset&&i.height===s.height&&i.active===s.active))}function Ra(e){let t=__md_get("__palette")||{index:e.findIndex(r=>matchMedia(r.getAttribute("data-md-color-media")).matches)};return R(...e).pipe(re(r=>h(r,"change").pipe(m(()=>r))),q(e[Math.max(0,t.index)]),m(r=>({index:e.indexOf(r),color:{media:r.getAttribute("data-md-color-media"),scheme:r.getAttribute("data-md-color-scheme"),primary:r.getAttribute("data-md-color-primary"),accent:r.getAttribute("data-md-color-accent")}})),Z(1))}function jn(e){let t=W("input",e),r=S("meta",{name:"theme-color"});document.head.appendChild(r);let o=S("meta",{name:"color-scheme"});document.head.appendChild(o);let n=At("(prefers-color-scheme: light)");return H(()=>{let i=new x;return i.subscribe(s=>{if(document.body.setAttribute("data-md-color-switching",""),s.color.media==="(prefers-color-scheme)"){let a=matchMedia("(prefers-color-scheme: light)"),c=document.querySelector(a.matches?"[data-md-color-media='(prefers-color-scheme: light)']":"[data-md-color-media='(prefers-color-scheme: dark)']");s.color.scheme=c.getAttribute("data-md-color-scheme"),s.color.primary=c.getAttribute("data-md-color-primary"),s.color.accent=c.getAttribute("data-md-color-accent")}for(let[a,c]of Object.entries(s.color))document.body.setAttribute(`data-md-color-${a}`,c);for(let a=0;a{let s=Oe("header"),a=window.getComputedStyle(s);return o.content=a.colorScheme,a.backgroundColor.match(/\d+/g).map(c=>(+c).toString(16).padStart(2,"0")).join("")})).subscribe(s=>r.content=`#${s}`),i.pipe(Me(ie)).subscribe(()=>{document.body.removeAttribute("data-md-color-switching")}),Ra(t).pipe(j(n.pipe(Ee(1))),at(),T(s=>i.next(s)),A(()=>i.complete()),m(s=>P({ref:e},s)))})}function Wn(e,{progress$:t}){return H(()=>{let r=new x;return r.subscribe(({value:o})=>{e.style.setProperty("--md-progress-value",`${o}`)}),t.pipe(T(o=>r.next({value:o})),A(()=>r.complete()),m(o=>({ref:e,value:o})))})}var Yr=jt(Kr());function Ia(e){e.setAttribute("data-md-copying","");let t=e.closest("[data-copy]"),r=t?t.getAttribute("data-copy"):e.innerText;return e.removeAttribute("data-md-copying"),r.trimEnd()}function Un({alert$:e}){Yr.default.isSupported()&&new I(t=>{new Yr.default("[data-clipboard-target], [data-clipboard-text]",{text:r=>r.getAttribute("data-clipboard-text")||Ia(U(r.getAttribute("data-clipboard-target")))}).on("success",r=>t.next(r))}).pipe(T(t=>{t.trigger.focus()}),m(()=>we("clipboard.copied"))).subscribe(e)}function Fa(e){if(e.length<2)return[""];let[t,r]=[...e].sort((n,i)=>n.length-i.length).map(n=>n.replace(/[^/]+$/,"")),o=0;if(t===r)o=t.length;else for(;t.charCodeAt(o)===r.charCodeAt(o);)o++;return e.map(n=>n.replace(t.slice(0,o),""))}function ur(e){let t=__md_get("__sitemap",sessionStorage,e);if(t)return R(t);{let r=he();return on(new URL("sitemap.xml",e||r.base)).pipe(m(o=>Fa(W("loc",o).map(n=>n.textContent))),xe(()=>M),$e([]),T(o=>__md_set("__sitemap",o,sessionStorage,e)))}}function Nn(e){let t=ce("[rel=canonical]",e);typeof t!="undefined"&&(t.href=t.href.replace("//localhost:","//127.0.0.1:"));let r=new Map;for(let o of W(":scope > *",e)){let n=o.outerHTML;for(let i of["href","src"]){let s=o.getAttribute(i);if(s===null)continue;let a=new URL(s,t==null?void 0:t.href),c=o.cloneNode();c.setAttribute(i,`${a}`),n=c.outerHTML;break}r.set(n,o)}return r}function Dn({location$:e,viewport$:t,progress$:r}){let o=he();if(location.protocol==="file:")return M;let n=ur().pipe(m(l=>l.map(f=>`${new URL(f,o.base)}`))),i=h(document.body,"click").pipe(ae(n),w(([l,f])=>{if(!(l.target instanceof Element))return M;let u=l.target.closest("a");if(u===null)return M;if(u.target||l.metaKey||l.ctrlKey)return M;let d=new URL(u.href);return d.search=d.hash="",f.includes(`${d}`)?(l.preventDefault(),R(new URL(u.href))):M}),de());i.pipe(ue(1)).subscribe(()=>{let l=ce("link[rel=icon]");typeof l!="undefined"&&(l.href=l.href)}),h(window,"beforeunload").subscribe(()=>{history.scrollRestoration="auto"}),i.pipe(ae(t)).subscribe(([l,{offset:f}])=>{history.scrollRestoration="manual",history.replaceState(f,""),history.pushState(null,"",l)}),i.subscribe(e);let s=e.pipe(q(me()),te("pathname"),Ee(1),w(l=>lr(l,{progress$:r}).pipe(xe(()=>(st(l,!0),M))))),a=new DOMParser,c=s.pipe(w(l=>l.text()),w(l=>{let f=a.parseFromString(l,"text/html");for(let b of["[data-md-component=announce]","[data-md-component=container]","[data-md-component=header-topic]","[data-md-component=outdated]","[data-md-component=logo]","[data-md-component=skip]",...G("navigation.tabs.sticky")?["[data-md-component=tabs]"]:[]]){let D=ce(b),Q=ce(b,f);typeof D!="undefined"&&typeof Q!="undefined"&&D.replaceWith(Q)}let u=Nn(document.head),d=Nn(f.head);for(let[b,D]of d)D.getAttribute("rel")==="stylesheet"||D.hasAttribute("src")||(u.has(b)?u.delete(b):document.head.appendChild(D));for(let b of u.values())b.getAttribute("rel")==="stylesheet"||b.hasAttribute("src")||b.remove();let y=Oe("container");return We(W("script",y)).pipe(w(b=>{let D=f.createElement("script");if(b.src){for(let Q of b.getAttributeNames())D.setAttribute(Q,b.getAttribute(Q));return b.replaceWith(D),new I(Q=>{D.onload=()=>Q.complete()})}else return D.textContent=b.textContent,b.replaceWith(D),M}),ee(),oe(f))}),de());return h(window,"popstate").pipe(m(me)).subscribe(e),e.pipe(q(me()),Ce(2,1),v(([l,f])=>l.pathname===f.pathname&&l.hash!==f.hash),m(([,l])=>l)).subscribe(l=>{var f,u;history.state!==null||!l.hash?window.scrollTo(0,(u=(f=history.state)==null?void 0:f.y)!=null?u:0):(history.scrollRestoration="auto",pr(l.hash),history.scrollRestoration="manual")}),e.pipe(Ir(i),q(me()),Ce(2,1),v(([l,f])=>l.pathname===f.pathname&&l.hash===f.hash),m(([,l])=>l)).subscribe(l=>{history.scrollRestoration="auto",pr(l.hash),history.scrollRestoration="manual",history.back()}),c.pipe(ae(e)).subscribe(([,l])=>{var f,u;history.state!==null||!l.hash?window.scrollTo(0,(u=(f=history.state)==null?void 0:f.y)!=null?u:0):pr(l.hash)}),t.pipe(te("offset"),ye(100)).subscribe(({offset:l})=>{history.replaceState(l,"")}),c}var qn=jt(zn());function Kn(e){let t=e.separator.split("|").map(n=>n.replace(/(\(\?[!=<][^)]+\))/g,"").length===0?"\uFFFD":n).join("|"),r=new RegExp(t,"img"),o=(n,i,s)=>`${i}${s}`;return n=>{n=n.replace(/[\s*+\-:~^]+/g," ").trim();let i=new RegExp(`(^|${e.separator}|)(${n.replace(/[|\\{}()[\]^$+*?.-]/g,"\\$&").replace(r,"|")})`,"img");return s=>(0,qn.default)(s).replace(i,o).replace(/<\/mark>(\s+)]*>/img,"$1")}}function Ht(e){return e.type===1}function dr(e){return e.type===3}function Qn(e,t){let r=ln(e);return L(R(location.protocol!=="file:"),Ne("search")).pipe(Pe(o=>o),w(()=>t)).subscribe(({config:o,docs:n})=>r.next({type:0,data:{config:o,docs:n,options:{suggest:G("search.suggest")}}})),r}function Yn({document$:e}){let t=he(),r=De(new URL("../versions.json",t.base)).pipe(xe(()=>M)),o=r.pipe(m(n=>{let[,i]=t.base.match(/([^/]+)\/?$/);return n.find(({version:s,aliases:a})=>s===i||a.includes(i))||n[0]}));r.pipe(m(n=>new Map(n.map(i=>[`${new URL(`../${i.version}/`,t.base)}`,i]))),w(n=>h(document.body,"click").pipe(v(i=>!i.metaKey&&!i.ctrlKey),ae(o),w(([i,s])=>{if(i.target instanceof Element){let a=i.target.closest("a");if(a&&!a.target&&n.has(a.href)){let c=a.href;return!i.target.closest(".md-version")&&n.get(c)===s?M:(i.preventDefault(),R(c))}}return M}),w(i=>{let{version:s}=n.get(i);return ur(new URL(i)).pipe(m(a=>{let p=me().href.replace(t.base,"");return a.includes(p.split("#")[0])?new URL(`../${s}/${p}`,t.base):new URL(i)}))})))).subscribe(n=>st(n,!0)),B([r,o]).subscribe(([n,i])=>{U(".md-header__topic").appendChild(gn(n,i))}),e.pipe(w(()=>o)).subscribe(n=>{var s;let i=__md_get("__outdated",sessionStorage);if(i===null){i=!0;let a=((s=t.version)==null?void 0:s.default)||"latest";Array.isArray(a)||(a=[a]);e:for(let c of a)for(let p of n.aliases.concat(n.version))if(new RegExp(c,"i").test(p)){i=!1;break e}__md_set("__outdated",i,sessionStorage)}if(i)for(let a of ne("outdated"))a.hidden=!1})}function Da(e,{worker$:t}){let{searchParams:r}=me();r.has("q")&&(Ye("search",!0),e.value=r.get("q"),e.focus(),Ne("search").pipe(Pe(i=>!i)).subscribe(()=>{let i=me();i.searchParams.delete("q"),history.replaceState({},"",`${i}`)}));let o=vt(e),n=L(t.pipe(Pe(Ht)),h(e,"keyup"),o).pipe(m(()=>e.value),X());return B([n,o]).pipe(m(([i,s])=>({value:i,focus:s})),Z(1))}function Bn(e,{worker$:t}){let r=new x,o=r.pipe(ee(),oe(!0));B([t.pipe(Pe(Ht)),r],(i,s)=>s).pipe(te("value")).subscribe(({value:i})=>t.next({type:2,data:i})),r.pipe(te("focus")).subscribe(({focus:i})=>{i&&Ye("search",i)}),h(e.form,"reset").pipe(j(o)).subscribe(()=>e.focus());let n=U("header [for=__search]");return h(n,"click").subscribe(()=>e.focus()),Da(e,{worker$:t}).pipe(T(i=>r.next(i)),A(()=>r.complete()),m(i=>P({ref:e},i)),Z(1))}function Gn(e,{worker$:t,query$:r}){let o=new x,n=Go(e.parentElement).pipe(v(Boolean)),i=e.parentElement,s=U(":scope > :first-child",e),a=U(":scope > :last-child",e);Ne("search").subscribe(l=>a.setAttribute("role",l?"list":"presentation")),o.pipe(ae(r),Wr(t.pipe(Pe(Ht)))).subscribe(([{items:l},{value:f}])=>{switch(l.length){case 0:s.textContent=f.length?we("search.result.none"):we("search.result.placeholder");break;case 1:s.textContent=we("search.result.one");break;default:let u=ar(l.length);s.textContent=we("search.result.other",u)}});let c=o.pipe(T(()=>a.innerHTML=""),w(({items:l})=>L(R(...l.slice(0,10)),R(...l.slice(10)).pipe(Ce(4),Nr(n),w(([f])=>f)))),m(hn),de());return c.subscribe(l=>a.appendChild(l)),c.pipe(re(l=>{let f=ce("details",l);return typeof f=="undefined"?M:h(f,"toggle").pipe(j(o),m(()=>f))})).subscribe(l=>{l.open===!1&&l.offsetTop<=i.scrollTop&&i.scrollTo({top:l.offsetTop})}),t.pipe(v(dr),m(({data:l})=>l)).pipe(T(l=>o.next(l)),A(()=>o.complete()),m(l=>P({ref:e},l)))}function Va(e,{query$:t}){return t.pipe(m(({value:r})=>{let o=me();return o.hash="",r=r.replace(/\s+/g,"+").replace(/&/g,"%26").replace(/=/g,"%3D"),o.search=`q=${r}`,{url:o}}))}function Jn(e,t){let r=new x,o=r.pipe(ee(),oe(!0));return r.subscribe(({url:n})=>{e.setAttribute("data-clipboard-text",e.href),e.href=`${n}`}),h(e,"click").pipe(j(o)).subscribe(n=>n.preventDefault()),Va(e,t).pipe(T(n=>r.next(n)),A(()=>r.complete()),m(n=>P({ref:e},n)))}function Xn(e,{worker$:t,keyboard$:r}){let o=new x,n=Oe("search-query"),i=L(h(n,"keydown"),h(n,"focus")).pipe(Me(ie),m(()=>n.value),X());return o.pipe(Ze(i),m(([{suggest:a},c])=>{let p=c.split(/([\s-]+)/);if(a!=null&&a.length&&p[p.length-1]){let l=a[a.length-1];l.startsWith(p[p.length-1])&&(p[p.length-1]=l)}else p.length=0;return p})).subscribe(a=>e.innerHTML=a.join("").replace(/\s/g," ")),r.pipe(v(({mode:a})=>a==="search")).subscribe(a=>{switch(a.type){case"ArrowRight":e.innerText.length&&n.selectionStart===n.value.length&&(n.value=e.innerText);break}}),t.pipe(v(dr),m(({data:a})=>a)).pipe(T(a=>o.next(a)),A(()=>o.complete()),m(()=>({ref:e})))}function Zn(e,{index$:t,keyboard$:r}){let o=he();try{let n=Qn(o.search,t),i=Oe("search-query",e),s=Oe("search-result",e);h(e,"click").pipe(v(({target:c})=>c instanceof Element&&!!c.closest("a"))).subscribe(()=>Ye("search",!1)),r.pipe(v(({mode:c})=>c==="search")).subscribe(c=>{let p=Ie();switch(c.type){case"Enter":if(p===i){let l=new Map;for(let f of W(":first-child [href]",s)){let u=f.firstElementChild;l.set(f,parseFloat(u.getAttribute("data-md-score")))}if(l.size){let[[f]]=[...l].sort(([,u],[,d])=>d-u);f.click()}c.claim()}break;case"Escape":case"Tab":Ye("search",!1),i.blur();break;case"ArrowUp":case"ArrowDown":if(typeof p=="undefined")i.focus();else{let l=[i,...W(":not(details) > [href], summary, details[open] [href]",s)],f=Math.max(0,(Math.max(0,l.indexOf(p))+l.length+(c.type==="ArrowUp"?-1:1))%l.length);l[f].focus()}c.claim();break;default:i!==Ie()&&i.focus()}}),r.pipe(v(({mode:c})=>c==="global")).subscribe(c=>{switch(c.type){case"f":case"s":case"/":i.focus(),i.select(),c.claim();break}});let a=Bn(i,{worker$:n});return L(a,Gn(s,{worker$:n,query$:a})).pipe(Re(...ne("search-share",e).map(c=>Jn(c,{query$:a})),...ne("search-suggest",e).map(c=>Xn(c,{worker$:n,keyboard$:r}))))}catch(n){return e.hidden=!0,Ke}}function ei(e,{index$:t,location$:r}){return B([t,r.pipe(q(me()),v(o=>!!o.searchParams.get("h")))]).pipe(m(([o,n])=>Kn(o.config)(n.searchParams.get("h"))),m(o=>{var s;let n=new Map,i=document.createNodeIterator(e,NodeFilter.SHOW_TEXT);for(let a=i.nextNode();a;a=i.nextNode())if((s=a.parentElement)!=null&&s.offsetHeight){let c=a.textContent,p=o(c);p.length>c.length&&n.set(a,p)}for(let[a,c]of n){let{childNodes:p}=S("span",null,c);a.replaceWith(...Array.from(p))}return{ref:e,nodes:n}}))}function za(e,{viewport$:t,main$:r}){let o=e.closest(".md-grid"),n=o.offsetTop-o.parentElement.offsetTop;return B([r,t]).pipe(m(([{offset:i,height:s},{offset:{y:a}}])=>(s=s+Math.min(n,Math.max(0,a-i))-n,{height:s,locked:a>=i+n})),X((i,s)=>i.height===s.height&&i.locked===s.locked))}function Br(e,o){var n=o,{header$:t}=n,r=oo(n,["header$"]);let i=U(".md-sidebar__scrollwrap",e),{y:s}=Ue(i);return H(()=>{let a=new x,c=a.pipe(ee(),oe(!0)),p=a.pipe(Le(0,ge));return p.pipe(ae(t)).subscribe({next([{height:l},{height:f}]){i.style.height=`${l-2*s}px`,e.style.top=`${f}px`},complete(){i.style.height="",e.style.top=""}}),p.pipe(Pe()).subscribe(()=>{for(let l of W(".md-nav__link--active[href]",e)){if(!l.clientHeight)continue;let f=l.closest(".md-sidebar__scrollwrap");if(typeof f!="undefined"){let u=l.offsetTop-f.offsetTop,{height:d}=le(f);f.scrollTo({top:u-d/2})}}}),fe(W("label[tabindex]",e)).pipe(re(l=>h(l,"click").pipe(Me(ie),m(()=>l),j(c)))).subscribe(l=>{let f=U(`[id="${l.htmlFor}"]`);U(`[aria-labelledby="${l.id}"]`).setAttribute("aria-expanded",`${f.checked}`)}),za(e,r).pipe(T(l=>a.next(l)),A(()=>a.complete()),m(l=>P({ref:e},l)))})}function ti(e,t){if(typeof t!="undefined"){let r=`https://api.github.com/repos/${e}/${t}`;return Lt(De(`${r}/releases/latest`).pipe(xe(()=>M),m(o=>({version:o.tag_name})),$e({})),De(r).pipe(xe(()=>M),m(o=>({stars:o.stargazers_count,forks:o.forks_count})),$e({}))).pipe(m(([o,n])=>P(P({},o),n)))}else{let r=`https://api.github.com/users/${e}`;return De(r).pipe(m(o=>({repositories:o.public_repos})),$e({}))}}function ri(e,t){let r=`https://${e}/api/v4/projects/${encodeURIComponent(t)}`;return De(r).pipe(xe(()=>M),m(({star_count:o,forks_count:n})=>({stars:o,forks:n})),$e({}))}function oi(e){let t=e.match(/^.+github\.com\/([^/]+)\/?([^/]+)?/i);if(t){let[,r,o]=t;return ti(r,o)}if(t=e.match(/^.+?([^/]*gitlab[^/]+)\/(.+?)\/?$/i),t){let[,r,o]=t;return ri(r,o)}return M}var qa;function Ka(e){return qa||(qa=H(()=>{let t=__md_get("__source",sessionStorage);if(t)return R(t);if(ne("consent").length){let o=__md_get("__consent");if(!(o&&o.github))return M}return oi(e.href).pipe(T(o=>__md_set("__source",o,sessionStorage)))}).pipe(xe(()=>M),v(t=>Object.keys(t).length>0),m(t=>({facts:t})),Z(1)))}function ni(e){let t=U(":scope > :last-child",e);return H(()=>{let r=new x;return r.subscribe(({facts:o})=>{t.appendChild(bn(o)),t.classList.add("md-source__repository--active")}),Ka(e).pipe(T(o=>r.next(o)),A(()=>r.complete()),m(o=>P({ref:e},o)))})}function Qa(e,{viewport$:t,header$:r}){return Se(document.body).pipe(w(()=>mr(e,{header$:r,viewport$:t})),m(({offset:{y:o}})=>({hidden:o>=10})),te("hidden"))}function ii(e,t){return H(()=>{let r=new x;return r.subscribe({next({hidden:o}){e.hidden=o},complete(){e.hidden=!1}}),(G("navigation.tabs.sticky")?R({hidden:!1}):Qa(e,t)).pipe(T(o=>r.next(o)),A(()=>r.complete()),m(o=>P({ref:e},o)))})}function Ya(e,{viewport$:t,header$:r}){let o=new Map,n=W("[href^=\\#]",e);for(let a of n){let c=decodeURIComponent(a.hash.substring(1)),p=ce(`[id="${c}"]`);typeof p!="undefined"&&o.set(a,p)}let i=r.pipe(te("height"),m(({height:a})=>{let c=Oe("main"),p=U(":scope > :first-child",c);return a+.8*(p.offsetTop-c.offsetTop)}),de());return Se(document.body).pipe(te("height"),w(a=>H(()=>{let c=[];return R([...o].reduce((p,[l,f])=>{for(;c.length&&o.get(c[c.length-1]).tagName>=f.tagName;)c.pop();let u=f.offsetTop;for(;!u&&f.parentElement;)f=f.parentElement,u=f.offsetTop;let d=f.offsetParent;for(;d;d=d.offsetParent)u+=d.offsetTop;return p.set([...c=[...c,l]].reverse(),u)},new Map))}).pipe(m(c=>new Map([...c].sort(([,p],[,l])=>p-l))),Ze(i),w(([c,p])=>t.pipe(Fr(([l,f],{offset:{y:u},size:d})=>{let y=u+d.height>=Math.floor(a.height);for(;f.length;){let[,b]=f[0];if(b-p=u&&!y)f=[l.pop(),...f];else break}return[l,f]},[[],[...c]]),X((l,f)=>l[0]===f[0]&&l[1]===f[1])))))).pipe(m(([a,c])=>({prev:a.map(([p])=>p),next:c.map(([p])=>p)})),q({prev:[],next:[]}),Ce(2,1),m(([a,c])=>a.prev.length{let i=new x,s=i.pipe(ee(),oe(!0));if(i.subscribe(({prev:a,next:c})=>{for(let[p]of c)p.classList.remove("md-nav__link--passed"),p.classList.remove("md-nav__link--active");for(let[p,[l]]of a.entries())l.classList.add("md-nav__link--passed"),l.classList.toggle("md-nav__link--active",p===a.length-1)}),G("toc.follow")){let a=L(t.pipe(ye(1),m(()=>{})),t.pipe(ye(250),m(()=>"smooth")));i.pipe(v(({prev:c})=>c.length>0),Ze(o.pipe(Me(ie))),ae(a)).subscribe(([[{prev:c}],p])=>{let[l]=c[c.length-1];if(l.offsetHeight){let f=sr(l);if(typeof f!="undefined"){let u=l.offsetTop-f.offsetTop,{height:d}=le(f);f.scrollTo({top:u-d/2,behavior:p})}}})}return G("navigation.tracking")&&t.pipe(j(s),te("offset"),ye(250),Ee(1),j(n.pipe(Ee(1))),at({delay:250}),ae(i)).subscribe(([,{prev:a}])=>{let c=me(),p=a[a.length-1];if(p&&p.length){let[l]=p,{hash:f}=new URL(l.href);c.hash!==f&&(c.hash=f,history.replaceState({},"",`${c}`))}else c.hash="",history.replaceState({},"",`${c}`)}),Ya(e,{viewport$:t,header$:r}).pipe(T(a=>i.next(a)),A(()=>i.complete()),m(a=>P({ref:e},a)))})}function Ba(e,{viewport$:t,main$:r,target$:o}){let n=t.pipe(m(({offset:{y:s}})=>s),Ce(2,1),m(([s,a])=>s>a&&a>0),X()),i=r.pipe(m(({active:s})=>s));return B([i,n]).pipe(m(([s,a])=>!(s&&a)),X(),j(o.pipe(Ee(1))),oe(!0),at({delay:250}),m(s=>({hidden:s})))}function si(e,{viewport$:t,header$:r,main$:o,target$:n}){let i=new x,s=i.pipe(ee(),oe(!0));return i.subscribe({next({hidden:a}){e.hidden=a,a?(e.setAttribute("tabindex","-1"),e.blur()):e.removeAttribute("tabindex")},complete(){e.style.top="",e.hidden=!0,e.removeAttribute("tabindex")}}),r.pipe(j(s),te("height")).subscribe(({height:a})=>{e.style.top=`${a+16}px`}),h(e,"click").subscribe(a=>{a.preventDefault(),window.scrollTo({top:0})}),Ba(e,{viewport$:t,main$:o,target$:n}).pipe(T(a=>i.next(a)),A(()=>i.complete()),m(a=>P({ref:e},a)))}function ci({document$:e}){e.pipe(w(()=>W(".md-ellipsis")),re(t=>yt(t).pipe(j(e.pipe(Ee(1))),v(r=>r),m(()=>t),ue(1))),v(t=>t.offsetWidth{let r=t.innerText,o=t.closest("a")||t;return o.title=r,Be(o).pipe(j(e.pipe(Ee(1))),A(()=>o.removeAttribute("title")))})).subscribe(),e.pipe(w(()=>W(".md-status")),re(t=>Be(t))).subscribe()}function pi({document$:e,tablet$:t}){e.pipe(w(()=>W(".md-toggle--indeterminate")),T(r=>{r.indeterminate=!0,r.checked=!1}),re(r=>h(r,"change").pipe(Ur(()=>r.classList.contains("md-toggle--indeterminate")),m(()=>r))),ae(t)).subscribe(([r,o])=>{r.classList.remove("md-toggle--indeterminate"),o&&(r.checked=!1)})}function Ga(){return/(iPad|iPhone|iPod)/.test(navigator.userAgent)}function li({document$:e}){e.pipe(w(()=>W("[data-md-scrollfix]")),T(t=>t.removeAttribute("data-md-scrollfix")),v(Ga),re(t=>h(t,"touchstart").pipe(m(()=>t)))).subscribe(t=>{let r=t.scrollTop;r===0?t.scrollTop=1:r+t.offsetHeight===t.scrollHeight&&(t.scrollTop=r-1)})}function mi({viewport$:e,tablet$:t}){B([Ne("search"),t]).pipe(m(([r,o])=>r&&!o),w(r=>R(r).pipe(Qe(r?400:100))),ae(e)).subscribe(([r,{offset:{y:o}}])=>{if(r)document.body.setAttribute("data-md-scrolllock",""),document.body.style.top=`-${o}px`;else{let n=-1*parseInt(document.body.style.top,10);document.body.removeAttribute("data-md-scrolllock"),document.body.style.top="",n&&window.scrollTo(0,n)}})}Object.entries||(Object.entries=function(e){let t=[];for(let r of Object.keys(e))t.push([r,e[r]]);return t});Object.values||(Object.values=function(e){let t=[];for(let r of Object.keys(e))t.push(e[r]);return t});typeof Element!="undefined"&&(Element.prototype.scrollTo||(Element.prototype.scrollTo=function(e,t){typeof e=="object"?(this.scrollLeft=e.left,this.scrollTop=e.top):(this.scrollLeft=e,this.scrollTop=t)}),Element.prototype.replaceWith||(Element.prototype.replaceWith=function(...e){let t=this.parentNode;if(t){e.length===0&&t.removeChild(this);for(let r=e.length-1;r>=0;r--){let o=e[r];typeof o=="string"?o=document.createTextNode(o):o.parentNode&&o.parentNode.removeChild(o),r?t.insertBefore(this.previousSibling,o):t.replaceChild(o,this)}}}));function Ja(){return location.protocol==="file:"?gt(`${new URL("search/search_index.js",Gr.base)}`).pipe(m(()=>__index),Z(1)):De(new URL("search/search_index.json",Gr.base))}document.documentElement.classList.remove("no-js");document.documentElement.classList.add("js");var rt=zo(),Pt=Zo(),wt=tn(Pt),Jr=Xo(),_e=pn(),hr=At("(min-width: 960px)"),ui=At("(min-width: 1220px)"),di=rn(),Gr=he(),hi=document.forms.namedItem("search")?Ja():Ke,Xr=new x;Un({alert$:Xr});var Zr=new x;G("navigation.instant")&&Dn({location$:Pt,viewport$:_e,progress$:Zr}).subscribe(rt);var fi;((fi=Gr.version)==null?void 0:fi.provider)==="mike"&&Yn({document$:rt});L(Pt,wt).pipe(Qe(125)).subscribe(()=>{Ye("drawer",!1),Ye("search",!1)});Jr.pipe(v(({mode:e})=>e==="global")).subscribe(e=>{switch(e.type){case"p":case",":let t=ce("link[rel=prev]");typeof t!="undefined"&&st(t);break;case"n":case".":let r=ce("link[rel=next]");typeof r!="undefined"&&st(r);break;case"Enter":let o=Ie();o instanceof HTMLLabelElement&&o.click()}});ci({document$:rt});pi({document$:rt,tablet$:hr});li({document$:rt});mi({viewport$:_e,tablet$:hr});var tt=Pn(Oe("header"),{viewport$:_e}),$t=rt.pipe(m(()=>Oe("main")),w(e=>Fn(e,{viewport$:_e,header$:tt})),Z(1)),Xa=L(...ne("consent").map(e=>fn(e,{target$:wt})),...ne("dialog").map(e=>$n(e,{alert$:Xr})),...ne("header").map(e=>Rn(e,{viewport$:_e,header$:tt,main$:$t})),...ne("palette").map(e=>jn(e)),...ne("progress").map(e=>Wn(e,{progress$:Zr})),...ne("search").map(e=>Zn(e,{index$:hi,keyboard$:Jr})),...ne("source").map(e=>ni(e))),Za=H(()=>L(...ne("announce").map(e=>mn(e)),...ne("content").map(e=>Hn(e,{viewport$:_e,target$:wt,print$:di})),...ne("content").map(e=>G("search.highlight")?ei(e,{index$:hi,location$:Pt}):M),...ne("header-title").map(e=>In(e,{viewport$:_e,header$:tt})),...ne("sidebar").map(e=>e.getAttribute("data-md-type")==="navigation"?Dr(ui,()=>Br(e,{viewport$:_e,header$:tt,main$:$t})):Dr(hr,()=>Br(e,{viewport$:_e,header$:tt,main$:$t}))),...ne("tabs").map(e=>ii(e,{viewport$:_e,header$:tt})),...ne("toc").map(e=>ai(e,{viewport$:_e,header$:tt,main$:$t,target$:wt})),...ne("top").map(e=>si(e,{viewport$:_e,header$:tt,main$:$t,target$:wt})))),bi=rt.pipe(w(()=>Za),Re(Xa),Z(1));bi.subscribe();window.document$=rt;window.location$=Pt;window.target$=wt;window.keyboard$=Jr;window.viewport$=_e;window.tablet$=hr;window.screen$=ui;window.print$=di;window.alert$=Xr;window.progress$=Zr;window.component$=bi;})();
+//# sourceMappingURL=bundle.d7c377c4.min.js.map
+
diff --git a/assets/javascripts/bundle.d7c377c4.min.js.map b/assets/javascripts/bundle.d7c377c4.min.js.map
new file mode 100644
index 0000000..a57d388
--- /dev/null
+++ b/assets/javascripts/bundle.d7c377c4.min.js.map
@@ -0,0 +1,7 @@
+{
+ "version": 3,
+ "sources": ["node_modules/focus-visible/dist/focus-visible.js", "node_modules/clipboard/dist/clipboard.js", "node_modules/escape-html/index.js", "src/templates/assets/javascripts/bundle.ts", "node_modules/rxjs/node_modules/tslib/tslib.es6.js", "node_modules/rxjs/src/internal/util/isFunction.ts", "node_modules/rxjs/src/internal/util/createErrorClass.ts", "node_modules/rxjs/src/internal/util/UnsubscriptionError.ts", "node_modules/rxjs/src/internal/util/arrRemove.ts", "node_modules/rxjs/src/internal/Subscription.ts", "node_modules/rxjs/src/internal/config.ts", "node_modules/rxjs/src/internal/scheduler/timeoutProvider.ts", "node_modules/rxjs/src/internal/util/reportUnhandledError.ts", "node_modules/rxjs/src/internal/util/noop.ts", "node_modules/rxjs/src/internal/NotificationFactories.ts", "node_modules/rxjs/src/internal/util/errorContext.ts", "node_modules/rxjs/src/internal/Subscriber.ts", "node_modules/rxjs/src/internal/symbol/observable.ts", "node_modules/rxjs/src/internal/util/identity.ts", "node_modules/rxjs/src/internal/util/pipe.ts", "node_modules/rxjs/src/internal/Observable.ts", "node_modules/rxjs/src/internal/util/lift.ts", "node_modules/rxjs/src/internal/operators/OperatorSubscriber.ts", "node_modules/rxjs/src/internal/scheduler/animationFrameProvider.ts", "node_modules/rxjs/src/internal/util/ObjectUnsubscribedError.ts", "node_modules/rxjs/src/internal/Subject.ts", "node_modules/rxjs/src/internal/scheduler/dateTimestampProvider.ts", "node_modules/rxjs/src/internal/ReplaySubject.ts", "node_modules/rxjs/src/internal/scheduler/Action.ts", "node_modules/rxjs/src/internal/scheduler/intervalProvider.ts", "node_modules/rxjs/src/internal/scheduler/AsyncAction.ts", "node_modules/rxjs/src/internal/Scheduler.ts", "node_modules/rxjs/src/internal/scheduler/AsyncScheduler.ts", "node_modules/rxjs/src/internal/scheduler/async.ts", "node_modules/rxjs/src/internal/scheduler/AnimationFrameAction.ts", "node_modules/rxjs/src/internal/scheduler/AnimationFrameScheduler.ts", "node_modules/rxjs/src/internal/scheduler/animationFrame.ts", "node_modules/rxjs/src/internal/observable/empty.ts", "node_modules/rxjs/src/internal/util/isScheduler.ts", "node_modules/rxjs/src/internal/util/args.ts", "node_modules/rxjs/src/internal/util/isArrayLike.ts", "node_modules/rxjs/src/internal/util/isPromise.ts", "node_modules/rxjs/src/internal/util/isInteropObservable.ts", "node_modules/rxjs/src/internal/util/isAsyncIterable.ts", "node_modules/rxjs/src/internal/util/throwUnobservableError.ts", "node_modules/rxjs/src/internal/symbol/iterator.ts", "node_modules/rxjs/src/internal/util/isIterable.ts", "node_modules/rxjs/src/internal/util/isReadableStreamLike.ts", "node_modules/rxjs/src/internal/observable/innerFrom.ts", "node_modules/rxjs/src/internal/util/executeSchedule.ts", "node_modules/rxjs/src/internal/operators/observeOn.ts", "node_modules/rxjs/src/internal/operators/subscribeOn.ts", "node_modules/rxjs/src/internal/scheduled/scheduleObservable.ts", "node_modules/rxjs/src/internal/scheduled/schedulePromise.ts", "node_modules/rxjs/src/internal/scheduled/scheduleArray.ts", "node_modules/rxjs/src/internal/scheduled/scheduleIterable.ts", "node_modules/rxjs/src/internal/scheduled/scheduleAsyncIterable.ts", "node_modules/rxjs/src/internal/scheduled/scheduleReadableStreamLike.ts", "node_modules/rxjs/src/internal/scheduled/scheduled.ts", "node_modules/rxjs/src/internal/observable/from.ts", "node_modules/rxjs/src/internal/observable/of.ts", "node_modules/rxjs/src/internal/observable/throwError.ts", "node_modules/rxjs/src/internal/util/EmptyError.ts", "node_modules/rxjs/src/internal/util/isDate.ts", "node_modules/rxjs/src/internal/operators/map.ts", "node_modules/rxjs/src/internal/util/mapOneOrManyArgs.ts", "node_modules/rxjs/src/internal/util/argsArgArrayOrObject.ts", "node_modules/rxjs/src/internal/util/createObject.ts", "node_modules/rxjs/src/internal/observable/combineLatest.ts", "node_modules/rxjs/src/internal/operators/mergeInternals.ts", "node_modules/rxjs/src/internal/operators/mergeMap.ts", "node_modules/rxjs/src/internal/operators/mergeAll.ts", "node_modules/rxjs/src/internal/operators/concatAll.ts", "node_modules/rxjs/src/internal/observable/concat.ts", "node_modules/rxjs/src/internal/observable/defer.ts", "node_modules/rxjs/src/internal/observable/fromEvent.ts", "node_modules/rxjs/src/internal/observable/fromEventPattern.ts", "node_modules/rxjs/src/internal/observable/timer.ts", "node_modules/rxjs/src/internal/observable/merge.ts", "node_modules/rxjs/src/internal/observable/never.ts", "node_modules/rxjs/src/internal/util/argsOrArgArray.ts", "node_modules/rxjs/src/internal/operators/filter.ts", "node_modules/rxjs/src/internal/observable/zip.ts", "node_modules/rxjs/src/internal/operators/audit.ts", "node_modules/rxjs/src/internal/operators/auditTime.ts", "node_modules/rxjs/src/internal/operators/bufferCount.ts", "node_modules/rxjs/src/internal/operators/catchError.ts", "node_modules/rxjs/src/internal/operators/scanInternals.ts", "node_modules/rxjs/src/internal/operators/combineLatest.ts", "node_modules/rxjs/src/internal/operators/combineLatestWith.ts", "node_modules/rxjs/src/internal/operators/debounceTime.ts", "node_modules/rxjs/src/internal/operators/defaultIfEmpty.ts", "node_modules/rxjs/src/internal/operators/take.ts", "node_modules/rxjs/src/internal/operators/ignoreElements.ts", "node_modules/rxjs/src/internal/operators/mapTo.ts", "node_modules/rxjs/src/internal/operators/delayWhen.ts", "node_modules/rxjs/src/internal/operators/delay.ts", "node_modules/rxjs/src/internal/operators/distinctUntilChanged.ts", "node_modules/rxjs/src/internal/operators/distinctUntilKeyChanged.ts", "node_modules/rxjs/src/internal/operators/throwIfEmpty.ts", "node_modules/rxjs/src/internal/operators/endWith.ts", "node_modules/rxjs/src/internal/operators/finalize.ts", "node_modules/rxjs/src/internal/operators/first.ts", "node_modules/rxjs/src/internal/operators/takeLast.ts", "node_modules/rxjs/src/internal/operators/merge.ts", "node_modules/rxjs/src/internal/operators/mergeWith.ts", "node_modules/rxjs/src/internal/operators/repeat.ts", "node_modules/rxjs/src/internal/operators/sample.ts", "node_modules/rxjs/src/internal/operators/scan.ts", "node_modules/rxjs/src/internal/operators/share.ts", "node_modules/rxjs/src/internal/operators/shareReplay.ts", "node_modules/rxjs/src/internal/operators/skip.ts", "node_modules/rxjs/src/internal/operators/skipUntil.ts", "node_modules/rxjs/src/internal/operators/startWith.ts", "node_modules/rxjs/src/internal/operators/switchMap.ts", "node_modules/rxjs/src/internal/operators/takeUntil.ts", "node_modules/rxjs/src/internal/operators/takeWhile.ts", "node_modules/rxjs/src/internal/operators/tap.ts", "node_modules/rxjs/src/internal/operators/throttle.ts", "node_modules/rxjs/src/internal/operators/throttleTime.ts", "node_modules/rxjs/src/internal/operators/withLatestFrom.ts", "node_modules/rxjs/src/internal/operators/zip.ts", "node_modules/rxjs/src/internal/operators/zipWith.ts", "src/templates/assets/javascripts/browser/document/index.ts", "src/templates/assets/javascripts/browser/element/_/index.ts", "src/templates/assets/javascripts/browser/element/focus/index.ts", "src/templates/assets/javascripts/browser/element/hover/index.ts", "src/templates/assets/javascripts/browser/element/offset/_/index.ts", "src/templates/assets/javascripts/browser/element/offset/content/index.ts", "src/templates/assets/javascripts/utilities/h/index.ts", "src/templates/assets/javascripts/utilities/round/index.ts", "src/templates/assets/javascripts/browser/script/index.ts", "src/templates/assets/javascripts/browser/element/size/_/index.ts", "src/templates/assets/javascripts/browser/element/size/content/index.ts", "src/templates/assets/javascripts/browser/element/visibility/index.ts", "src/templates/assets/javascripts/browser/toggle/index.ts", "src/templates/assets/javascripts/browser/keyboard/index.ts", "src/templates/assets/javascripts/browser/location/_/index.ts", "src/templates/assets/javascripts/browser/location/hash/index.ts", "src/templates/assets/javascripts/browser/media/index.ts", "src/templates/assets/javascripts/browser/request/index.ts", "src/templates/assets/javascripts/browser/viewport/offset/index.ts", "src/templates/assets/javascripts/browser/viewport/size/index.ts", "src/templates/assets/javascripts/browser/viewport/_/index.ts", "src/templates/assets/javascripts/browser/viewport/at/index.ts", "src/templates/assets/javascripts/browser/worker/index.ts", "src/templates/assets/javascripts/_/index.ts", "src/templates/assets/javascripts/components/_/index.ts", "src/templates/assets/javascripts/components/announce/index.ts", "src/templates/assets/javascripts/components/consent/index.ts", "src/templates/assets/javascripts/templates/tooltip/index.tsx", "src/templates/assets/javascripts/templates/annotation/index.tsx", "src/templates/assets/javascripts/templates/clipboard/index.tsx", "src/templates/assets/javascripts/templates/search/index.tsx", "src/templates/assets/javascripts/templates/source/index.tsx", "src/templates/assets/javascripts/templates/tabbed/index.tsx", "src/templates/assets/javascripts/templates/table/index.tsx", "src/templates/assets/javascripts/templates/version/index.tsx", "src/templates/assets/javascripts/components/tooltip/index.ts", "src/templates/assets/javascripts/components/content/annotation/_/index.ts", "src/templates/assets/javascripts/components/content/annotation/list/index.ts", "src/templates/assets/javascripts/components/content/annotation/block/index.ts", "src/templates/assets/javascripts/components/content/code/_/index.ts", "src/templates/assets/javascripts/components/content/details/index.ts", "src/templates/assets/javascripts/components/content/mermaid/index.css", "src/templates/assets/javascripts/components/content/mermaid/index.ts", "src/templates/assets/javascripts/components/content/table/index.ts", "src/templates/assets/javascripts/components/content/tabs/index.ts", "src/templates/assets/javascripts/components/content/_/index.ts", "src/templates/assets/javascripts/components/dialog/index.ts", "src/templates/assets/javascripts/components/header/_/index.ts", "src/templates/assets/javascripts/components/header/title/index.ts", "src/templates/assets/javascripts/components/main/index.ts", "src/templates/assets/javascripts/components/palette/index.ts", "src/templates/assets/javascripts/components/progress/index.ts", "src/templates/assets/javascripts/integrations/clipboard/index.ts", "src/templates/assets/javascripts/integrations/sitemap/index.ts", "src/templates/assets/javascripts/integrations/instant/index.ts", "src/templates/assets/javascripts/integrations/search/highlighter/index.ts", "src/templates/assets/javascripts/integrations/search/worker/message/index.ts", "src/templates/assets/javascripts/integrations/search/worker/_/index.ts", "src/templates/assets/javascripts/integrations/version/index.ts", "src/templates/assets/javascripts/components/search/query/index.ts", "src/templates/assets/javascripts/components/search/result/index.ts", "src/templates/assets/javascripts/components/search/share/index.ts", "src/templates/assets/javascripts/components/search/suggest/index.ts", "src/templates/assets/javascripts/components/search/_/index.ts", "src/templates/assets/javascripts/components/search/highlight/index.ts", "src/templates/assets/javascripts/components/sidebar/index.ts", "src/templates/assets/javascripts/components/source/facts/github/index.ts", "src/templates/assets/javascripts/components/source/facts/gitlab/index.ts", "src/templates/assets/javascripts/components/source/facts/_/index.ts", "src/templates/assets/javascripts/components/source/_/index.ts", "src/templates/assets/javascripts/components/tabs/index.ts", "src/templates/assets/javascripts/components/toc/index.ts", "src/templates/assets/javascripts/components/top/index.ts", "src/templates/assets/javascripts/patches/ellipsis/index.ts", "src/templates/assets/javascripts/patches/indeterminate/index.ts", "src/templates/assets/javascripts/patches/scrollfix/index.ts", "src/templates/assets/javascripts/patches/scrolllock/index.ts", "src/templates/assets/javascripts/polyfills/index.ts"],
+ "sourcesContent": ["(function (global, factory) {\n typeof exports === 'object' && typeof module !== 'undefined' ? factory() :\n typeof define === 'function' && define.amd ? define(factory) :\n (factory());\n}(this, (function () { 'use strict';\n\n /**\n * Applies the :focus-visible polyfill at the given scope.\n * A scope in this case is either the top-level Document or a Shadow Root.\n *\n * @param {(Document|ShadowRoot)} scope\n * @see https://github.com/WICG/focus-visible\n */\n function applyFocusVisiblePolyfill(scope) {\n var hadKeyboardEvent = true;\n var hadFocusVisibleRecently = false;\n var hadFocusVisibleRecentlyTimeout = null;\n\n var inputTypesAllowlist = {\n text: true,\n search: true,\n url: true,\n tel: true,\n email: true,\n password: true,\n number: true,\n date: true,\n month: true,\n week: true,\n time: true,\n datetime: true,\n 'datetime-local': true\n };\n\n /**\n * Helper function for legacy browsers and iframes which sometimes focus\n * elements like document, body, and non-interactive SVG.\n * @param {Element} el\n */\n function isValidFocusTarget(el) {\n if (\n el &&\n el !== document &&\n el.nodeName !== 'HTML' &&\n el.nodeName !== 'BODY' &&\n 'classList' in el &&\n 'contains' in el.classList\n ) {\n return true;\n }\n return false;\n }\n\n /**\n * Computes whether the given element should automatically trigger the\n * `focus-visible` class being added, i.e. whether it should always match\n * `:focus-visible` when focused.\n * @param {Element} el\n * @return {boolean}\n */\n function focusTriggersKeyboardModality(el) {\n var type = el.type;\n var tagName = el.tagName;\n\n if (tagName === 'INPUT' && inputTypesAllowlist[type] && !el.readOnly) {\n return true;\n }\n\n if (tagName === 'TEXTAREA' && !el.readOnly) {\n return true;\n }\n\n if (el.isContentEditable) {\n return true;\n }\n\n return false;\n }\n\n /**\n * Add the `focus-visible` class to the given element if it was not added by\n * the author.\n * @param {Element} el\n */\n function addFocusVisibleClass(el) {\n if (el.classList.contains('focus-visible')) {\n return;\n }\n el.classList.add('focus-visible');\n el.setAttribute('data-focus-visible-added', '');\n }\n\n /**\n * Remove the `focus-visible` class from the given element if it was not\n * originally added by the author.\n * @param {Element} el\n */\n function removeFocusVisibleClass(el) {\n if (!el.hasAttribute('data-focus-visible-added')) {\n return;\n }\n el.classList.remove('focus-visible');\n el.removeAttribute('data-focus-visible-added');\n }\n\n /**\n * If the most recent user interaction was via the keyboard;\n * and the key press did not include a meta, alt/option, or control key;\n * then the modality is keyboard. Otherwise, the modality is not keyboard.\n * Apply `focus-visible` to any current active element and keep track\n * of our keyboard modality state with `hadKeyboardEvent`.\n * @param {KeyboardEvent} e\n */\n function onKeyDown(e) {\n if (e.metaKey || e.altKey || e.ctrlKey) {\n return;\n }\n\n if (isValidFocusTarget(scope.activeElement)) {\n addFocusVisibleClass(scope.activeElement);\n }\n\n hadKeyboardEvent = true;\n }\n\n /**\n * If at any point a user clicks with a pointing device, ensure that we change\n * the modality away from keyboard.\n * This avoids the situation where a user presses a key on an already focused\n * element, and then clicks on a different element, focusing it with a\n * pointing device, while we still think we're in keyboard modality.\n * @param {Event} e\n */\n function onPointerDown(e) {\n hadKeyboardEvent = false;\n }\n\n /**\n * On `focus`, add the `focus-visible` class to the target if:\n * - the target received focus as a result of keyboard navigation, or\n * - the event target is an element that will likely require interaction\n * via the keyboard (e.g. a text box)\n * @param {Event} e\n */\n function onFocus(e) {\n // Prevent IE from focusing the document or HTML element.\n if (!isValidFocusTarget(e.target)) {\n return;\n }\n\n if (hadKeyboardEvent || focusTriggersKeyboardModality(e.target)) {\n addFocusVisibleClass(e.target);\n }\n }\n\n /**\n * On `blur`, remove the `focus-visible` class from the target.\n * @param {Event} e\n */\n function onBlur(e) {\n if (!isValidFocusTarget(e.target)) {\n return;\n }\n\n if (\n e.target.classList.contains('focus-visible') ||\n e.target.hasAttribute('data-focus-visible-added')\n ) {\n // To detect a tab/window switch, we look for a blur event followed\n // rapidly by a visibility change.\n // If we don't see a visibility change within 100ms, it's probably a\n // regular focus change.\n hadFocusVisibleRecently = true;\n window.clearTimeout(hadFocusVisibleRecentlyTimeout);\n hadFocusVisibleRecentlyTimeout = window.setTimeout(function() {\n hadFocusVisibleRecently = false;\n }, 100);\n removeFocusVisibleClass(e.target);\n }\n }\n\n /**\n * If the user changes tabs, keep track of whether or not the previously\n * focused element had .focus-visible.\n * @param {Event} e\n */\n function onVisibilityChange(e) {\n if (document.visibilityState === 'hidden') {\n // If the tab becomes active again, the browser will handle calling focus\n // on the element (Safari actually calls it twice).\n // If this tab change caused a blur on an element with focus-visible,\n // re-apply the class when the user switches back to the tab.\n if (hadFocusVisibleRecently) {\n hadKeyboardEvent = true;\n }\n addInitialPointerMoveListeners();\n }\n }\n\n /**\n * Add a group of listeners to detect usage of any pointing devices.\n * These listeners will be added when the polyfill first loads, and anytime\n * the window is blurred, so that they are active when the window regains\n * focus.\n */\n function addInitialPointerMoveListeners() {\n document.addEventListener('mousemove', onInitialPointerMove);\n document.addEventListener('mousedown', onInitialPointerMove);\n document.addEventListener('mouseup', onInitialPointerMove);\n document.addEventListener('pointermove', onInitialPointerMove);\n document.addEventListener('pointerdown', onInitialPointerMove);\n document.addEventListener('pointerup', onInitialPointerMove);\n document.addEventListener('touchmove', onInitialPointerMove);\n document.addEventListener('touchstart', onInitialPointerMove);\n document.addEventListener('touchend', onInitialPointerMove);\n }\n\n function removeInitialPointerMoveListeners() {\n document.removeEventListener('mousemove', onInitialPointerMove);\n document.removeEventListener('mousedown', onInitialPointerMove);\n document.removeEventListener('mouseup', onInitialPointerMove);\n document.removeEventListener('pointermove', onInitialPointerMove);\n document.removeEventListener('pointerdown', onInitialPointerMove);\n document.removeEventListener('pointerup', onInitialPointerMove);\n document.removeEventListener('touchmove', onInitialPointerMove);\n document.removeEventListener('touchstart', onInitialPointerMove);\n document.removeEventListener('touchend', onInitialPointerMove);\n }\n\n /**\n * When the polfyill first loads, assume the user is in keyboard modality.\n * If any event is received from a pointing device (e.g. mouse, pointer,\n * touch), turn off keyboard modality.\n * This accounts for situations where focus enters the page from the URL bar.\n * @param {Event} e\n */\n function onInitialPointerMove(e) {\n // Work around a Safari quirk that fires a mousemove on whenever the\n // window blurs, even if you're tabbing out of the page. \u00AF\\_(\u30C4)_/\u00AF\n if (e.target.nodeName && e.target.nodeName.toLowerCase() === 'html') {\n return;\n }\n\n hadKeyboardEvent = false;\n removeInitialPointerMoveListeners();\n }\n\n // For some kinds of state, we are interested in changes at the global scope\n // only. For example, global pointer input, global key presses and global\n // visibility change should affect the state at every scope:\n document.addEventListener('keydown', onKeyDown, true);\n document.addEventListener('mousedown', onPointerDown, true);\n document.addEventListener('pointerdown', onPointerDown, true);\n document.addEventListener('touchstart', onPointerDown, true);\n document.addEventListener('visibilitychange', onVisibilityChange, true);\n\n addInitialPointerMoveListeners();\n\n // For focus and blur, we specifically care about state changes in the local\n // scope. This is because focus / blur events that originate from within a\n // shadow root are not re-dispatched from the host element if it was already\n // the active element in its own scope:\n scope.addEventListener('focus', onFocus, true);\n scope.addEventListener('blur', onBlur, true);\n\n // We detect that a node is a ShadowRoot by ensuring that it is a\n // DocumentFragment and also has a host property. This check covers native\n // implementation and polyfill implementation transparently. If we only cared\n // about the native implementation, we could just check if the scope was\n // an instance of a ShadowRoot.\n if (scope.nodeType === Node.DOCUMENT_FRAGMENT_NODE && scope.host) {\n // Since a ShadowRoot is a special kind of DocumentFragment, it does not\n // have a root element to add a class to. So, we add this attribute to the\n // host element instead:\n scope.host.setAttribute('data-js-focus-visible', '');\n } else if (scope.nodeType === Node.DOCUMENT_NODE) {\n document.documentElement.classList.add('js-focus-visible');\n document.documentElement.setAttribute('data-js-focus-visible', '');\n }\n }\n\n // It is important to wrap all references to global window and document in\n // these checks to support server-side rendering use cases\n // @see https://github.com/WICG/focus-visible/issues/199\n if (typeof window !== 'undefined' && typeof document !== 'undefined') {\n // Make the polyfill helper globally available. This can be used as a signal\n // to interested libraries that wish to coordinate with the polyfill for e.g.,\n // applying the polyfill to a shadow root:\n window.applyFocusVisiblePolyfill = applyFocusVisiblePolyfill;\n\n // Notify interested libraries of the polyfill's presence, in case the\n // polyfill was loaded lazily:\n var event;\n\n try {\n event = new CustomEvent('focus-visible-polyfill-ready');\n } catch (error) {\n // IE11 does not support using CustomEvent as a constructor directly:\n event = document.createEvent('CustomEvent');\n event.initCustomEvent('focus-visible-polyfill-ready', false, false, {});\n }\n\n window.dispatchEvent(event);\n }\n\n if (typeof document !== 'undefined') {\n // Apply the polyfill to the global document, so that no JavaScript\n // coordination is required to use the polyfill in the top-level document:\n applyFocusVisiblePolyfill(document);\n }\n\n})));\n", "/*!\n * clipboard.js v2.0.11\n * https://clipboardjs.com/\n *\n * Licensed MIT \u00A9 Zeno Rocha\n */\n(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"ClipboardJS\"] = factory();\n\telse\n\t\troot[\"ClipboardJS\"] = factory();\n})(this, function() {\nreturn /******/ (function() { // webpackBootstrap\n/******/ \tvar __webpack_modules__ = ({\n\n/***/ 686:\n/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {\n\n\"use strict\";\n\n// EXPORTS\n__webpack_require__.d(__webpack_exports__, {\n \"default\": function() { return /* binding */ clipboard; }\n});\n\n// EXTERNAL MODULE: ./node_modules/tiny-emitter/index.js\nvar tiny_emitter = __webpack_require__(279);\nvar tiny_emitter_default = /*#__PURE__*/__webpack_require__.n(tiny_emitter);\n// EXTERNAL MODULE: ./node_modules/good-listener/src/listen.js\nvar listen = __webpack_require__(370);\nvar listen_default = /*#__PURE__*/__webpack_require__.n(listen);\n// EXTERNAL MODULE: ./node_modules/select/src/select.js\nvar src_select = __webpack_require__(817);\nvar select_default = /*#__PURE__*/__webpack_require__.n(src_select);\n;// CONCATENATED MODULE: ./src/common/command.js\n/**\n * Executes a given operation type.\n * @param {String} type\n * @return {Boolean}\n */\nfunction command(type) {\n try {\n return document.execCommand(type);\n } catch (err) {\n return false;\n }\n}\n;// CONCATENATED MODULE: ./src/actions/cut.js\n\n\n/**\n * Cut action wrapper.\n * @param {String|HTMLElement} target\n * @return {String}\n */\n\nvar ClipboardActionCut = function ClipboardActionCut(target) {\n var selectedText = select_default()(target);\n command('cut');\n return selectedText;\n};\n\n/* harmony default export */ var actions_cut = (ClipboardActionCut);\n;// CONCATENATED MODULE: ./src/common/create-fake-element.js\n/**\n * Creates a fake textarea element with a value.\n * @param {String} value\n * @return {HTMLElement}\n */\nfunction createFakeElement(value) {\n var isRTL = document.documentElement.getAttribute('dir') === 'rtl';\n var fakeElement = document.createElement('textarea'); // Prevent zooming on iOS\n\n fakeElement.style.fontSize = '12pt'; // Reset box model\n\n fakeElement.style.border = '0';\n fakeElement.style.padding = '0';\n fakeElement.style.margin = '0'; // Move element out of screen horizontally\n\n fakeElement.style.position = 'absolute';\n fakeElement.style[isRTL ? 'right' : 'left'] = '-9999px'; // Move element to the same position vertically\n\n var yPosition = window.pageYOffset || document.documentElement.scrollTop;\n fakeElement.style.top = \"\".concat(yPosition, \"px\");\n fakeElement.setAttribute('readonly', '');\n fakeElement.value = value;\n return fakeElement;\n}\n;// CONCATENATED MODULE: ./src/actions/copy.js\n\n\n\n/**\n * Create fake copy action wrapper using a fake element.\n * @param {String} target\n * @param {Object} options\n * @return {String}\n */\n\nvar fakeCopyAction = function fakeCopyAction(value, options) {\n var fakeElement = createFakeElement(value);\n options.container.appendChild(fakeElement);\n var selectedText = select_default()(fakeElement);\n command('copy');\n fakeElement.remove();\n return selectedText;\n};\n/**\n * Copy action wrapper.\n * @param {String|HTMLElement} target\n * @param {Object} options\n * @return {String}\n */\n\n\nvar ClipboardActionCopy = function ClipboardActionCopy(target) {\n var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {\n container: document.body\n };\n var selectedText = '';\n\n if (typeof target === 'string') {\n selectedText = fakeCopyAction(target, options);\n } else if (target instanceof HTMLInputElement && !['text', 'search', 'url', 'tel', 'password'].includes(target === null || target === void 0 ? void 0 : target.type)) {\n // If input type doesn't support `setSelectionRange`. Simulate it. https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setSelectionRange\n selectedText = fakeCopyAction(target.value, options);\n } else {\n selectedText = select_default()(target);\n command('copy');\n }\n\n return selectedText;\n};\n\n/* harmony default export */ var actions_copy = (ClipboardActionCopy);\n;// CONCATENATED MODULE: ./src/actions/default.js\nfunction _typeof(obj) { \"@babel/helpers - typeof\"; if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof(obj); }\n\n\n\n/**\n * Inner function which performs selection from either `text` or `target`\n * properties and then executes copy or cut operations.\n * @param {Object} options\n */\n\nvar ClipboardActionDefault = function ClipboardActionDefault() {\n var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n // Defines base properties passed from constructor.\n var _options$action = options.action,\n action = _options$action === void 0 ? 'copy' : _options$action,\n container = options.container,\n target = options.target,\n text = options.text; // Sets the `action` to be performed which can be either 'copy' or 'cut'.\n\n if (action !== 'copy' && action !== 'cut') {\n throw new Error('Invalid \"action\" value, use either \"copy\" or \"cut\"');\n } // Sets the `target` property using an element that will be have its content copied.\n\n\n if (target !== undefined) {\n if (target && _typeof(target) === 'object' && target.nodeType === 1) {\n if (action === 'copy' && target.hasAttribute('disabled')) {\n throw new Error('Invalid \"target\" attribute. Please use \"readonly\" instead of \"disabled\" attribute');\n }\n\n if (action === 'cut' && (target.hasAttribute('readonly') || target.hasAttribute('disabled'))) {\n throw new Error('Invalid \"target\" attribute. You can\\'t cut text from elements with \"readonly\" or \"disabled\" attributes');\n }\n } else {\n throw new Error('Invalid \"target\" value, use a valid Element');\n }\n } // Define selection strategy based on `text` property.\n\n\n if (text) {\n return actions_copy(text, {\n container: container\n });\n } // Defines which selection strategy based on `target` property.\n\n\n if (target) {\n return action === 'cut' ? actions_cut(target) : actions_copy(target, {\n container: container\n });\n }\n};\n\n/* harmony default export */ var actions_default = (ClipboardActionDefault);\n;// CONCATENATED MODULE: ./src/clipboard.js\nfunction clipboard_typeof(obj) { \"@babel/helpers - typeof\"; if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { clipboard_typeof = function _typeof(obj) { return typeof obj; }; } else { clipboard_typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return clipboard_typeof(obj); }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function\"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }\n\nfunction _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }\n\nfunction _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }\n\nfunction _possibleConstructorReturn(self, call) { if (call && (clipboard_typeof(call) === \"object\" || typeof call === \"function\")) { return call; } return _assertThisInitialized(self); }\n\nfunction _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return self; }\n\nfunction _isNativeReflectConstruct() { if (typeof Reflect === \"undefined\" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === \"function\") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }\n\nfunction _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }\n\n\n\n\n\n\n/**\n * Helper function to retrieve attribute value.\n * @param {String} suffix\n * @param {Element} element\n */\n\nfunction getAttributeValue(suffix, element) {\n var attribute = \"data-clipboard-\".concat(suffix);\n\n if (!element.hasAttribute(attribute)) {\n return;\n }\n\n return element.getAttribute(attribute);\n}\n/**\n * Base class which takes one or more elements, adds event listeners to them,\n * and instantiates a new `ClipboardAction` on each click.\n */\n\n\nvar Clipboard = /*#__PURE__*/function (_Emitter) {\n _inherits(Clipboard, _Emitter);\n\n var _super = _createSuper(Clipboard);\n\n /**\n * @param {String|HTMLElement|HTMLCollection|NodeList} trigger\n * @param {Object} options\n */\n function Clipboard(trigger, options) {\n var _this;\n\n _classCallCheck(this, Clipboard);\n\n _this = _super.call(this);\n\n _this.resolveOptions(options);\n\n _this.listenClick(trigger);\n\n return _this;\n }\n /**\n * Defines if attributes would be resolved using internal setter functions\n * or custom functions that were passed in the constructor.\n * @param {Object} options\n */\n\n\n _createClass(Clipboard, [{\n key: \"resolveOptions\",\n value: function resolveOptions() {\n var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n this.action = typeof options.action === 'function' ? options.action : this.defaultAction;\n this.target = typeof options.target === 'function' ? options.target : this.defaultTarget;\n this.text = typeof options.text === 'function' ? options.text : this.defaultText;\n this.container = clipboard_typeof(options.container) === 'object' ? options.container : document.body;\n }\n /**\n * Adds a click event listener to the passed trigger.\n * @param {String|HTMLElement|HTMLCollection|NodeList} trigger\n */\n\n }, {\n key: \"listenClick\",\n value: function listenClick(trigger) {\n var _this2 = this;\n\n this.listener = listen_default()(trigger, 'click', function (e) {\n return _this2.onClick(e);\n });\n }\n /**\n * Defines a new `ClipboardAction` on each click event.\n * @param {Event} e\n */\n\n }, {\n key: \"onClick\",\n value: function onClick(e) {\n var trigger = e.delegateTarget || e.currentTarget;\n var action = this.action(trigger) || 'copy';\n var text = actions_default({\n action: action,\n container: this.container,\n target: this.target(trigger),\n text: this.text(trigger)\n }); // Fires an event based on the copy operation result.\n\n this.emit(text ? 'success' : 'error', {\n action: action,\n text: text,\n trigger: trigger,\n clearSelection: function clearSelection() {\n if (trigger) {\n trigger.focus();\n }\n\n window.getSelection().removeAllRanges();\n }\n });\n }\n /**\n * Default `action` lookup function.\n * @param {Element} trigger\n */\n\n }, {\n key: \"defaultAction\",\n value: function defaultAction(trigger) {\n return getAttributeValue('action', trigger);\n }\n /**\n * Default `target` lookup function.\n * @param {Element} trigger\n */\n\n }, {\n key: \"defaultTarget\",\n value: function defaultTarget(trigger) {\n var selector = getAttributeValue('target', trigger);\n\n if (selector) {\n return document.querySelector(selector);\n }\n }\n /**\n * Allow fire programmatically a copy action\n * @param {String|HTMLElement} target\n * @param {Object} options\n * @returns Text copied.\n */\n\n }, {\n key: \"defaultText\",\n\n /**\n * Default `text` lookup function.\n * @param {Element} trigger\n */\n value: function defaultText(trigger) {\n return getAttributeValue('text', trigger);\n }\n /**\n * Destroy lifecycle.\n */\n\n }, {\n key: \"destroy\",\n value: function destroy() {\n this.listener.destroy();\n }\n }], [{\n key: \"copy\",\n value: function copy(target) {\n var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {\n container: document.body\n };\n return actions_copy(target, options);\n }\n /**\n * Allow fire programmatically a cut action\n * @param {String|HTMLElement} target\n * @returns Text cutted.\n */\n\n }, {\n key: \"cut\",\n value: function cut(target) {\n return actions_cut(target);\n }\n /**\n * Returns the support of the given action, or all actions if no action is\n * given.\n * @param {String} [action]\n */\n\n }, {\n key: \"isSupported\",\n value: function isSupported() {\n var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ['copy', 'cut'];\n var actions = typeof action === 'string' ? [action] : action;\n var support = !!document.queryCommandSupported;\n actions.forEach(function (action) {\n support = support && !!document.queryCommandSupported(action);\n });\n return support;\n }\n }]);\n\n return Clipboard;\n}((tiny_emitter_default()));\n\n/* harmony default export */ var clipboard = (Clipboard);\n\n/***/ }),\n\n/***/ 828:\n/***/ (function(module) {\n\nvar DOCUMENT_NODE_TYPE = 9;\n\n/**\n * A polyfill for Element.matches()\n */\nif (typeof Element !== 'undefined' && !Element.prototype.matches) {\n var proto = Element.prototype;\n\n proto.matches = proto.matchesSelector ||\n proto.mozMatchesSelector ||\n proto.msMatchesSelector ||\n proto.oMatchesSelector ||\n proto.webkitMatchesSelector;\n}\n\n/**\n * Finds the closest parent that matches a selector.\n *\n * @param {Element} element\n * @param {String} selector\n * @return {Function}\n */\nfunction closest (element, selector) {\n while (element && element.nodeType !== DOCUMENT_NODE_TYPE) {\n if (typeof element.matches === 'function' &&\n element.matches(selector)) {\n return element;\n }\n element = element.parentNode;\n }\n}\n\nmodule.exports = closest;\n\n\n/***/ }),\n\n/***/ 438:\n/***/ (function(module, __unused_webpack_exports, __webpack_require__) {\n\nvar closest = __webpack_require__(828);\n\n/**\n * Delegates event to a selector.\n *\n * @param {Element} element\n * @param {String} selector\n * @param {String} type\n * @param {Function} callback\n * @param {Boolean} useCapture\n * @return {Object}\n */\nfunction _delegate(element, selector, type, callback, useCapture) {\n var listenerFn = listener.apply(this, arguments);\n\n element.addEventListener(type, listenerFn, useCapture);\n\n return {\n destroy: function() {\n element.removeEventListener(type, listenerFn, useCapture);\n }\n }\n}\n\n/**\n * Delegates event to a selector.\n *\n * @param {Element|String|Array} [elements]\n * @param {String} selector\n * @param {String} type\n * @param {Function} callback\n * @param {Boolean} useCapture\n * @return {Object}\n */\nfunction delegate(elements, selector, type, callback, useCapture) {\n // Handle the regular Element usage\n if (typeof elements.addEventListener === 'function') {\n return _delegate.apply(null, arguments);\n }\n\n // Handle Element-less usage, it defaults to global delegation\n if (typeof type === 'function') {\n // Use `document` as the first parameter, then apply arguments\n // This is a short way to .unshift `arguments` without running into deoptimizations\n return _delegate.bind(null, document).apply(null, arguments);\n }\n\n // Handle Selector-based usage\n if (typeof elements === 'string') {\n elements = document.querySelectorAll(elements);\n }\n\n // Handle Array-like based usage\n return Array.prototype.map.call(elements, function (element) {\n return _delegate(element, selector, type, callback, useCapture);\n });\n}\n\n/**\n * Finds closest match and invokes callback.\n *\n * @param {Element} element\n * @param {String} selector\n * @param {String} type\n * @param {Function} callback\n * @return {Function}\n */\nfunction listener(element, selector, type, callback) {\n return function(e) {\n e.delegateTarget = closest(e.target, selector);\n\n if (e.delegateTarget) {\n callback.call(element, e);\n }\n }\n}\n\nmodule.exports = delegate;\n\n\n/***/ }),\n\n/***/ 879:\n/***/ (function(__unused_webpack_module, exports) {\n\n/**\n * Check if argument is a HTML element.\n *\n * @param {Object} value\n * @return {Boolean}\n */\nexports.node = function(value) {\n return value !== undefined\n && value instanceof HTMLElement\n && value.nodeType === 1;\n};\n\n/**\n * Check if argument is a list of HTML elements.\n *\n * @param {Object} value\n * @return {Boolean}\n */\nexports.nodeList = function(value) {\n var type = Object.prototype.toString.call(value);\n\n return value !== undefined\n && (type === '[object NodeList]' || type === '[object HTMLCollection]')\n && ('length' in value)\n && (value.length === 0 || exports.node(value[0]));\n};\n\n/**\n * Check if argument is a string.\n *\n * @param {Object} value\n * @return {Boolean}\n */\nexports.string = function(value) {\n return typeof value === 'string'\n || value instanceof String;\n};\n\n/**\n * Check if argument is a function.\n *\n * @param {Object} value\n * @return {Boolean}\n */\nexports.fn = function(value) {\n var type = Object.prototype.toString.call(value);\n\n return type === '[object Function]';\n};\n\n\n/***/ }),\n\n/***/ 370:\n/***/ (function(module, __unused_webpack_exports, __webpack_require__) {\n\nvar is = __webpack_require__(879);\nvar delegate = __webpack_require__(438);\n\n/**\n * Validates all params and calls the right\n * listener function based on its target type.\n *\n * @param {String|HTMLElement|HTMLCollection|NodeList} target\n * @param {String} type\n * @param {Function} callback\n * @return {Object}\n */\nfunction listen(target, type, callback) {\n if (!target && !type && !callback) {\n throw new Error('Missing required arguments');\n }\n\n if (!is.string(type)) {\n throw new TypeError('Second argument must be a String');\n }\n\n if (!is.fn(callback)) {\n throw new TypeError('Third argument must be a Function');\n }\n\n if (is.node(target)) {\n return listenNode(target, type, callback);\n }\n else if (is.nodeList(target)) {\n return listenNodeList(target, type, callback);\n }\n else if (is.string(target)) {\n return listenSelector(target, type, callback);\n }\n else {\n throw new TypeError('First argument must be a String, HTMLElement, HTMLCollection, or NodeList');\n }\n}\n\n/**\n * Adds an event listener to a HTML element\n * and returns a remove listener function.\n *\n * @param {HTMLElement} node\n * @param {String} type\n * @param {Function} callback\n * @return {Object}\n */\nfunction listenNode(node, type, callback) {\n node.addEventListener(type, callback);\n\n return {\n destroy: function() {\n node.removeEventListener(type, callback);\n }\n }\n}\n\n/**\n * Add an event listener to a list of HTML elements\n * and returns a remove listener function.\n *\n * @param {NodeList|HTMLCollection} nodeList\n * @param {String} type\n * @param {Function} callback\n * @return {Object}\n */\nfunction listenNodeList(nodeList, type, callback) {\n Array.prototype.forEach.call(nodeList, function(node) {\n node.addEventListener(type, callback);\n });\n\n return {\n destroy: function() {\n Array.prototype.forEach.call(nodeList, function(node) {\n node.removeEventListener(type, callback);\n });\n }\n }\n}\n\n/**\n * Add an event listener to a selector\n * and returns a remove listener function.\n *\n * @param {String} selector\n * @param {String} type\n * @param {Function} callback\n * @return {Object}\n */\nfunction listenSelector(selector, type, callback) {\n return delegate(document.body, selector, type, callback);\n}\n\nmodule.exports = listen;\n\n\n/***/ }),\n\n/***/ 817:\n/***/ (function(module) {\n\nfunction select(element) {\n var selectedText;\n\n if (element.nodeName === 'SELECT') {\n element.focus();\n\n selectedText = element.value;\n }\n else if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') {\n var isReadOnly = element.hasAttribute('readonly');\n\n if (!isReadOnly) {\n element.setAttribute('readonly', '');\n }\n\n element.select();\n element.setSelectionRange(0, element.value.length);\n\n if (!isReadOnly) {\n element.removeAttribute('readonly');\n }\n\n selectedText = element.value;\n }\n else {\n if (element.hasAttribute('contenteditable')) {\n element.focus();\n }\n\n var selection = window.getSelection();\n var range = document.createRange();\n\n range.selectNodeContents(element);\n selection.removeAllRanges();\n selection.addRange(range);\n\n selectedText = selection.toString();\n }\n\n return selectedText;\n}\n\nmodule.exports = select;\n\n\n/***/ }),\n\n/***/ 279:\n/***/ (function(module) {\n\nfunction E () {\n // Keep this empty so it's easier to inherit from\n // (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)\n}\n\nE.prototype = {\n on: function (name, callback, ctx) {\n var e = this.e || (this.e = {});\n\n (e[name] || (e[name] = [])).push({\n fn: callback,\n ctx: ctx\n });\n\n return this;\n },\n\n once: function (name, callback, ctx) {\n var self = this;\n function listener () {\n self.off(name, listener);\n callback.apply(ctx, arguments);\n };\n\n listener._ = callback\n return this.on(name, listener, ctx);\n },\n\n emit: function (name) {\n var data = [].slice.call(arguments, 1);\n var evtArr = ((this.e || (this.e = {}))[name] || []).slice();\n var i = 0;\n var len = evtArr.length;\n\n for (i; i < len; i++) {\n evtArr[i].fn.apply(evtArr[i].ctx, data);\n }\n\n return this;\n },\n\n off: function (name, callback) {\n var e = this.e || (this.e = {});\n var evts = e[name];\n var liveEvents = [];\n\n if (evts && callback) {\n for (var i = 0, len = evts.length; i < len; i++) {\n if (evts[i].fn !== callback && evts[i].fn._ !== callback)\n liveEvents.push(evts[i]);\n }\n }\n\n // Remove event from queue to prevent memory leak\n // Suggested by https://github.com/lazd\n // Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910\n\n (liveEvents.length)\n ? e[name] = liveEvents\n : delete e[name];\n\n return this;\n }\n};\n\nmodule.exports = E;\nmodule.exports.TinyEmitter = E;\n\n\n/***/ })\n\n/******/ \t});\n/************************************************************************/\n/******/ \t// The module cache\n/******/ \tvar __webpack_module_cache__ = {};\n/******/ \t\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(__webpack_module_cache__[moduleId]) {\n/******/ \t\t\treturn __webpack_module_cache__[moduleId].exports;\n/******/ \t\t}\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = __webpack_module_cache__[moduleId] = {\n/******/ \t\t\t// no module.id needed\n/******/ \t\t\t// no module.loaded needed\n/******/ \t\t\texports: {}\n/******/ \t\t};\n/******/ \t\n/******/ \t\t// Execute the module function\n/******/ \t\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n/******/ \t\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/ \t\n/************************************************************************/\n/******/ \t/* webpack/runtime/compat get default export */\n/******/ \t!function() {\n/******/ \t\t// getDefaultExport function for compatibility with non-harmony modules\n/******/ \t\t__webpack_require__.n = function(module) {\n/******/ \t\t\tvar getter = module && module.__esModule ?\n/******/ \t\t\t\tfunction() { return module['default']; } :\n/******/ \t\t\t\tfunction() { return module; };\n/******/ \t\t\t__webpack_require__.d(getter, { a: getter });\n/******/ \t\t\treturn getter;\n/******/ \t\t};\n/******/ \t}();\n/******/ \t\n/******/ \t/* webpack/runtime/define property getters */\n/******/ \t!function() {\n/******/ \t\t// define getter functions for harmony exports\n/******/ \t\t__webpack_require__.d = function(exports, definition) {\n/******/ \t\t\tfor(var key in definition) {\n/******/ \t\t\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n/******/ \t\t\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n/******/ \t\t\t\t}\n/******/ \t\t\t}\n/******/ \t\t};\n/******/ \t}();\n/******/ \t\n/******/ \t/* webpack/runtime/hasOwnProperty shorthand */\n/******/ \t!function() {\n/******/ \t\t__webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }\n/******/ \t}();\n/******/ \t\n/************************************************************************/\n/******/ \t// module exports must be returned from runtime so entry inlining is disabled\n/******/ \t// startup\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(686);\n/******/ })()\n.default;\n});", "/*!\n * escape-html\n * Copyright(c) 2012-2013 TJ Holowaychuk\n * Copyright(c) 2015 Andreas Lubbe\n * Copyright(c) 2015 Tiancheng \"Timothy\" Gu\n * MIT Licensed\n */\n\n'use strict';\n\n/**\n * Module variables.\n * @private\n */\n\nvar matchHtmlRegExp = /[\"'&<>]/;\n\n/**\n * Module exports.\n * @public\n */\n\nmodule.exports = escapeHtml;\n\n/**\n * Escape special characters in the given string of html.\n *\n * @param {string} string The string to escape for inserting into HTML\n * @return {string}\n * @public\n */\n\nfunction escapeHtml(string) {\n var str = '' + string;\n var match = matchHtmlRegExp.exec(str);\n\n if (!match) {\n return str;\n }\n\n var escape;\n var html = '';\n var index = 0;\n var lastIndex = 0;\n\n for (index = match.index; index < str.length; index++) {\n switch (str.charCodeAt(index)) {\n case 34: // \"\n escape = '"';\n break;\n case 38: // &\n escape = '&';\n break;\n case 39: // '\n escape = ''';\n break;\n case 60: // <\n escape = '<';\n break;\n case 62: // >\n escape = '>';\n break;\n default:\n continue;\n }\n\n if (lastIndex !== index) {\n html += str.substring(lastIndex, index);\n }\n\n lastIndex = index + 1;\n html += escape;\n }\n\n return lastIndex !== index\n ? html + str.substring(lastIndex, index)\n : html;\n}\n", "/*\n * Copyright (c) 2016-2023 Martin Donath \n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to\n * deal in the Software without restriction, including without limitation the\n * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n * sell copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n * IN THE SOFTWARE.\n */\n\nimport \"focus-visible\"\n\nimport {\n EMPTY,\n NEVER,\n Observable,\n Subject,\n defer,\n delay,\n filter,\n map,\n merge,\n mergeWith,\n shareReplay,\n switchMap\n} from \"rxjs\"\n\nimport { configuration, feature } from \"./_\"\nimport {\n at,\n getActiveElement,\n getOptionalElement,\n requestJSON,\n setLocation,\n setToggle,\n watchDocument,\n watchKeyboard,\n watchLocation,\n watchLocationTarget,\n watchMedia,\n watchPrint,\n watchScript,\n watchViewport\n} from \"./browser\"\nimport {\n getComponentElement,\n getComponentElements,\n mountAnnounce,\n mountBackToTop,\n mountConsent,\n mountContent,\n mountDialog,\n mountHeader,\n mountHeaderTitle,\n mountPalette,\n mountProgress,\n mountSearch,\n mountSearchHiglight,\n mountSidebar,\n mountSource,\n mountTableOfContents,\n mountTabs,\n watchHeader,\n watchMain\n} from \"./components\"\nimport {\n SearchIndex,\n setupClipboardJS,\n setupInstantNavigation,\n setupVersionSelector\n} from \"./integrations\"\nimport {\n patchEllipsis,\n patchIndeterminate,\n patchScrollfix,\n patchScrolllock\n} from \"./patches\"\nimport \"./polyfills\"\n\n/* ----------------------------------------------------------------------------\n * Functions - @todo refactor\n * ------------------------------------------------------------------------- */\n\n/**\n * Fetch search index\n *\n * @returns Search index observable\n */\nfunction fetchSearchIndex(): Observable {\n if (location.protocol === \"file:\") {\n return watchScript(\n `${new URL(\"search/search_index.js\", config.base)}`\n )\n .pipe(\n // @ts-ignore - @todo fix typings\n map(() => __index),\n shareReplay(1)\n )\n } else {\n return requestJSON(\n new URL(\"search/search_index.json\", config.base)\n )\n }\n}\n\n/* ----------------------------------------------------------------------------\n * Application\n * ------------------------------------------------------------------------- */\n\n/* Yay, JavaScript is available */\ndocument.documentElement.classList.remove(\"no-js\")\ndocument.documentElement.classList.add(\"js\")\n\n/* Set up navigation observables and subjects */\nconst document$ = watchDocument()\nconst location$ = watchLocation()\nconst target$ = watchLocationTarget(location$)\nconst keyboard$ = watchKeyboard()\n\n/* Set up media observables */\nconst viewport$ = watchViewport()\nconst tablet$ = watchMedia(\"(min-width: 960px)\")\nconst screen$ = watchMedia(\"(min-width: 1220px)\")\nconst print$ = watchPrint()\n\n/* Retrieve search index, if search is enabled */\nconst config = configuration()\nconst index$ = document.forms.namedItem(\"search\")\n ? fetchSearchIndex()\n : NEVER\n\n/* Set up Clipboard.js integration */\nconst alert$ = new Subject()\nsetupClipboardJS({ alert$ })\n\n/* Set up progress indicator */\nconst progress$ = new Subject()\n\n/* Set up instant navigation, if enabled */\nif (feature(\"navigation.instant\"))\n setupInstantNavigation({ location$, viewport$, progress$ })\n .subscribe(document$)\n\n/* Set up version selector */\nif (config.version?.provider === \"mike\")\n setupVersionSelector({ document$ })\n\n/* Always close drawer and search on navigation */\nmerge(location$, target$)\n .pipe(\n delay(125)\n )\n .subscribe(() => {\n setToggle(\"drawer\", false)\n setToggle(\"search\", false)\n })\n\n/* Set up global keyboard handlers */\nkeyboard$\n .pipe(\n filter(({ mode }) => mode === \"global\")\n )\n .subscribe(key => {\n switch (key.type) {\n\n /* Go to previous page */\n case \"p\":\n case \",\":\n const prev = getOptionalElement(\"link[rel=prev]\")\n if (typeof prev !== \"undefined\")\n setLocation(prev)\n break\n\n /* Go to next page */\n case \"n\":\n case \".\":\n const next = getOptionalElement(\"link[rel=next]\")\n if (typeof next !== \"undefined\")\n setLocation(next)\n break\n\n /* Expand navigation, see https://bit.ly/3ZjG5io */\n case \"Enter\":\n const active = getActiveElement()\n if (active instanceof HTMLLabelElement)\n active.click()\n }\n })\n\n/* Set up patches */\npatchEllipsis({ document$ })\npatchIndeterminate({ document$, tablet$ })\npatchScrollfix({ document$ })\npatchScrolllock({ viewport$, tablet$ })\n\n/* Set up header and main area observable */\nconst header$ = watchHeader(getComponentElement(\"header\"), { viewport$ })\nconst main$ = document$\n .pipe(\n map(() => getComponentElement(\"main\")),\n switchMap(el => watchMain(el, { viewport$, header$ })),\n shareReplay(1)\n )\n\n/* Set up control component observables */\nconst control$ = merge(\n\n /* Consent */\n ...getComponentElements(\"consent\")\n .map(el => mountConsent(el, { target$ })),\n\n /* Dialog */\n ...getComponentElements(\"dialog\")\n .map(el => mountDialog(el, { alert$ })),\n\n /* Header */\n ...getComponentElements(\"header\")\n .map(el => mountHeader(el, { viewport$, header$, main$ })),\n\n /* Color palette */\n ...getComponentElements(\"palette\")\n .map(el => mountPalette(el)),\n\n /* Progress bar */\n ...getComponentElements(\"progress\")\n .map(el => mountProgress(el, { progress$ })),\n\n /* Search */\n ...getComponentElements(\"search\")\n .map(el => mountSearch(el, { index$, keyboard$ })),\n\n /* Repository information */\n ...getComponentElements(\"source\")\n .map(el => mountSource(el))\n)\n\n/* Set up content component observables */\nconst content$ = defer(() => merge(\n\n /* Announcement bar */\n ...getComponentElements(\"announce\")\n .map(el => mountAnnounce(el)),\n\n /* Content */\n ...getComponentElements(\"content\")\n .map(el => mountContent(el, { viewport$, target$, print$ })),\n\n /* Search highlighting */\n ...getComponentElements(\"content\")\n .map(el => feature(\"search.highlight\")\n ? mountSearchHiglight(el, { index$, location$ })\n : EMPTY\n ),\n\n /* Header title */\n ...getComponentElements(\"header-title\")\n .map(el => mountHeaderTitle(el, { viewport$, header$ })),\n\n /* Sidebar */\n ...getComponentElements(\"sidebar\")\n .map(el => el.getAttribute(\"data-md-type\") === \"navigation\"\n ? at(screen$, () => mountSidebar(el, { viewport$, header$, main$ }))\n : at(tablet$, () => mountSidebar(el, { viewport$, header$, main$ }))\n ),\n\n /* Navigation tabs */\n ...getComponentElements(\"tabs\")\n .map(el => mountTabs(el, { viewport$, header$ })),\n\n /* Table of contents */\n ...getComponentElements(\"toc\")\n .map(el => mountTableOfContents(el, {\n viewport$, header$, main$, target$\n })),\n\n /* Back-to-top button */\n ...getComponentElements(\"top\")\n .map(el => mountBackToTop(el, { viewport$, header$, main$, target$ }))\n))\n\n/* Set up component observables */\nconst component$ = document$\n .pipe(\n switchMap(() => content$),\n mergeWith(control$),\n shareReplay(1)\n )\n\n/* Subscribe to all components */\ncomponent$.subscribe()\n\n/* ----------------------------------------------------------------------------\n * Exports\n * ------------------------------------------------------------------------- */\n\nwindow.document$ = document$ /* Document observable */\nwindow.location$ = location$ /* Location subject */\nwindow.target$ = target$ /* Location target observable */\nwindow.keyboard$ = keyboard$ /* Keyboard observable */\nwindow.viewport$ = viewport$ /* Viewport observable */\nwindow.tablet$ = tablet$ /* Media tablet observable */\nwindow.screen$ = screen$ /* Media screen observable */\nwindow.print$ = print$ /* Media print observable */\nwindow.alert$ = alert$ /* Alert subject */\nwindow.progress$ = progress$ /* Progress indicator subject */\nwindow.component$ = component$ /* Component observable */\n", "/*! *****************************************************************************\r\nCopyright (c) Microsoft Corporation.\r\n\r\nPermission to use, copy, modify, and/or distribute this software for any\r\npurpose with or without fee is hereby granted.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\r\nREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\r\nAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\r\nINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\r\nLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\r\nOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\r\nPERFORMANCE OF THIS SOFTWARE.\r\n***************************************************************************** */\r\n/* global Reflect, Promise */\r\n\r\nvar extendStatics = function(d, b) {\r\n extendStatics = Object.setPrototypeOf ||\r\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r\n function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };\r\n return extendStatics(d, b);\r\n};\r\n\r\nexport function __extends(d, b) {\r\n if (typeof b !== \"function\" && b !== null)\r\n throw new TypeError(\"Class extends value \" + String(b) + \" is not a constructor or null\");\r\n extendStatics(d, b);\r\n function __() { this.constructor = d; }\r\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r\n}\r\n\r\nexport var __assign = function() {\r\n __assign = Object.assign || function __assign(t) {\r\n for (var s, i = 1, n = arguments.length; i < n; i++) {\r\n s = arguments[i];\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];\r\n }\r\n return t;\r\n }\r\n return __assign.apply(this, arguments);\r\n}\r\n\r\nexport function __rest(s, e) {\r\n var t = {};\r\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\r\n t[p] = s[p];\r\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\r\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\r\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\r\n t[p[i]] = s[p[i]];\r\n }\r\n return t;\r\n}\r\n\r\nexport function __decorate(decorators, target, key, desc) {\r\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\r\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\r\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\r\n return c > 3 && r && Object.defineProperty(target, key, r), r;\r\n}\r\n\r\nexport function __param(paramIndex, decorator) {\r\n return function (target, key) { decorator(target, key, paramIndex); }\r\n}\r\n\r\nexport function __metadata(metadataKey, metadataValue) {\r\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(metadataKey, metadataValue);\r\n}\r\n\r\nexport function __awaiter(thisArg, _arguments, P, generator) {\r\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\r\n return new (P || (P = Promise))(function (resolve, reject) {\r\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\r\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\r\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\r\n step((generator = generator.apply(thisArg, _arguments || [])).next());\r\n });\r\n}\r\n\r\nexport function __generator(thisArg, body) {\r\n var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;\r\n return g = { next: verb(0), \"throw\": verb(1), \"return\": verb(2) }, typeof Symbol === \"function\" && (g[Symbol.iterator] = function() { return this; }), g;\r\n function verb(n) { return function (v) { return step([n, v]); }; }\r\n function step(op) {\r\n if (f) throw new TypeError(\"Generator is already executing.\");\r\n while (_) try {\r\n if (f = 1, y && (t = op[0] & 2 ? y[\"return\"] : op[0] ? y[\"throw\"] || ((t = y[\"return\"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;\r\n if (y = 0, t) op = [op[0] & 2, t.value];\r\n switch (op[0]) {\r\n case 0: case 1: t = op; break;\r\n case 4: _.label++; return { value: op[1], done: false };\r\n case 5: _.label++; y = op[1]; op = [0]; continue;\r\n case 7: op = _.ops.pop(); _.trys.pop(); continue;\r\n default:\r\n if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }\r\n if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }\r\n if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }\r\n if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }\r\n if (t[2]) _.ops.pop();\r\n _.trys.pop(); continue;\r\n }\r\n op = body.call(thisArg, _);\r\n } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }\r\n if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };\r\n }\r\n}\r\n\r\nexport var __createBinding = Object.create ? (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });\r\n}) : (function(o, m, k, k2) {\r\n if (k2 === undefined) k2 = k;\r\n o[k2] = m[k];\r\n});\r\n\r\nexport function __exportStar(m, o) {\r\n for (var p in m) if (p !== \"default\" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, m, p);\r\n}\r\n\r\nexport function __values(o) {\r\n var s = typeof Symbol === \"function\" && Symbol.iterator, m = s && o[s], i = 0;\r\n if (m) return m.call(o);\r\n if (o && typeof o.length === \"number\") return {\r\n next: function () {\r\n if (o && i >= o.length) o = void 0;\r\n return { value: o && o[i++], done: !o };\r\n }\r\n };\r\n throw new TypeError(s ? \"Object is not iterable.\" : \"Symbol.iterator is not defined.\");\r\n}\r\n\r\nexport function __read(o, n) {\r\n var m = typeof Symbol === \"function\" && o[Symbol.iterator];\r\n if (!m) return o;\r\n var i = m.call(o), r, ar = [], e;\r\n try {\r\n while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);\r\n }\r\n catch (error) { e = { error: error }; }\r\n finally {\r\n try {\r\n if (r && !r.done && (m = i[\"return\"])) m.call(i);\r\n }\r\n finally { if (e) throw e.error; }\r\n }\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spread() {\r\n for (var ar = [], i = 0; i < arguments.length; i++)\r\n ar = ar.concat(__read(arguments[i]));\r\n return ar;\r\n}\r\n\r\n/** @deprecated */\r\nexport function __spreadArrays() {\r\n for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;\r\n for (var r = Array(s), k = 0, i = 0; i < il; i++)\r\n for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)\r\n r[k] = a[j];\r\n return r;\r\n}\r\n\r\nexport function __spreadArray(to, from, pack) {\r\n if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {\r\n if (ar || !(i in from)) {\r\n if (!ar) ar = Array.prototype.slice.call(from, 0, i);\r\n ar[i] = from[i];\r\n }\r\n }\r\n return to.concat(ar || Array.prototype.slice.call(from));\r\n}\r\n\r\nexport function __await(v) {\r\n return this instanceof __await ? (this.v = v, this) : new __await(v);\r\n}\r\n\r\nexport function __asyncGenerator(thisArg, _arguments, generator) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var g = generator.apply(thisArg, _arguments || []), i, q = [];\r\n return i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i;\r\n function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }\r\n function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }\r\n function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }\r\n function fulfill(value) { resume(\"next\", value); }\r\n function reject(value) { resume(\"throw\", value); }\r\n function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }\r\n}\r\n\r\nexport function __asyncDelegator(o) {\r\n var i, p;\r\n return i = {}, verb(\"next\"), verb(\"throw\", function (e) { throw e; }), verb(\"return\"), i[Symbol.iterator] = function () { return this; }, i;\r\n function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === \"return\" } : f ? f(v) : v; } : f; }\r\n}\r\n\r\nexport function __asyncValues(o) {\r\n if (!Symbol.asyncIterator) throw new TypeError(\"Symbol.asyncIterator is not defined.\");\r\n var m = o[Symbol.asyncIterator], i;\r\n return m ? m.call(o) : (o = typeof __values === \"function\" ? __values(o) : o[Symbol.iterator](), i = {}, verb(\"next\"), verb(\"throw\"), verb(\"return\"), i[Symbol.asyncIterator] = function () { return this; }, i);\r\n function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }\r\n function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }\r\n}\r\n\r\nexport function __makeTemplateObject(cooked, raw) {\r\n if (Object.defineProperty) { Object.defineProperty(cooked, \"raw\", { value: raw }); } else { cooked.raw = raw; }\r\n return cooked;\r\n};\r\n\r\nvar __setModuleDefault = Object.create ? (function(o, v) {\r\n Object.defineProperty(o, \"default\", { enumerable: true, value: v });\r\n}) : function(o, v) {\r\n o[\"default\"] = v;\r\n};\r\n\r\nexport function __importStar(mod) {\r\n if (mod && mod.__esModule) return mod;\r\n var result = {};\r\n if (mod != null) for (var k in mod) if (k !== \"default\" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);\r\n __setModuleDefault(result, mod);\r\n return result;\r\n}\r\n\r\nexport function __importDefault(mod) {\r\n return (mod && mod.__esModule) ? mod : { default: mod };\r\n}\r\n\r\nexport function __classPrivateFieldGet(receiver, state, kind, f) {\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a getter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot read private member from an object whose class did not declare it\");\r\n return kind === \"m\" ? f : kind === \"a\" ? f.call(receiver) : f ? f.value : state.get(receiver);\r\n}\r\n\r\nexport function __classPrivateFieldSet(receiver, state, value, kind, f) {\r\n if (kind === \"m\") throw new TypeError(\"Private method is not writable\");\r\n if (kind === \"a\" && !f) throw new TypeError(\"Private accessor was defined without a setter\");\r\n if (typeof state === \"function\" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError(\"Cannot write private member to an object whose class did not declare it\");\r\n return (kind === \"a\" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;\r\n}\r\n", "/**\n * Returns true if the object is a function.\n * @param value The value to check\n */\nexport function isFunction(value: any): value is (...args: any[]) => any {\n return typeof value === 'function';\n}\n", "/**\n * Used to create Error subclasses until the community moves away from ES5.\n *\n * This is because compiling from TypeScript down to ES5 has issues with subclassing Errors\n * as well as other built-in types: https://github.com/Microsoft/TypeScript/issues/12123\n *\n * @param createImpl A factory function to create the actual constructor implementation. The returned\n * function should be a named function that calls `_super` internally.\n */\nexport function createErrorClass(createImpl: (_super: any) => any): T {\n const _super = (instance: any) => {\n Error.call(instance);\n instance.stack = new Error().stack;\n };\n\n const ctorFunc = createImpl(_super);\n ctorFunc.prototype = Object.create(Error.prototype);\n ctorFunc.prototype.constructor = ctorFunc;\n return ctorFunc;\n}\n", "import { createErrorClass } from './createErrorClass';\n\nexport interface UnsubscriptionError extends Error {\n readonly errors: any[];\n}\n\nexport interface UnsubscriptionErrorCtor {\n /**\n * @deprecated Internal implementation detail. Do not construct error instances.\n * Cannot be tagged as internal: https://github.com/ReactiveX/rxjs/issues/6269\n */\n new (errors: any[]): UnsubscriptionError;\n}\n\n/**\n * An error thrown when one or more errors have occurred during the\n * `unsubscribe` of a {@link Subscription}.\n */\nexport const UnsubscriptionError: UnsubscriptionErrorCtor = createErrorClass(\n (_super) =>\n function UnsubscriptionErrorImpl(this: any, errors: (Error | string)[]) {\n _super(this);\n this.message = errors\n ? `${errors.length} errors occurred during unsubscription:\n${errors.map((err, i) => `${i + 1}) ${err.toString()}`).join('\\n ')}`\n : '';\n this.name = 'UnsubscriptionError';\n this.errors = errors;\n }\n);\n", "/**\n * Removes an item from an array, mutating it.\n * @param arr The array to remove the item from\n * @param item The item to remove\n */\nexport function arrRemove(arr: T[] | undefined | null, item: T) {\n if (arr) {\n const index = arr.indexOf(item);\n 0 <= index && arr.splice(index, 1);\n }\n}\n", "import { isFunction } from './util/isFunction';\nimport { UnsubscriptionError } from './util/UnsubscriptionError';\nimport { SubscriptionLike, TeardownLogic, Unsubscribable } from './types';\nimport { arrRemove } from './util/arrRemove';\n\n/**\n * Represents a disposable resource, such as the execution of an Observable. A\n * Subscription has one important method, `unsubscribe`, that takes no argument\n * and just disposes the resource held by the subscription.\n *\n * Additionally, subscriptions may be grouped together through the `add()`\n * method, which will attach a child Subscription to the current Subscription.\n * When a Subscription is unsubscribed, all its children (and its grandchildren)\n * will be unsubscribed as well.\n *\n * @class Subscription\n */\nexport class Subscription implements SubscriptionLike {\n /** @nocollapse */\n public static EMPTY = (() => {\n const empty = new Subscription();\n empty.closed = true;\n return empty;\n })();\n\n /**\n * A flag to indicate whether this Subscription has already been unsubscribed.\n */\n public closed = false;\n\n private _parentage: Subscription[] | Subscription | null = null;\n\n /**\n * The list of registered finalizers to execute upon unsubscription. Adding and removing from this\n * list occurs in the {@link #add} and {@link #remove} methods.\n */\n private _finalizers: Exclude[] | null = null;\n\n /**\n * @param initialTeardown A function executed first as part of the finalization\n * process that is kicked off when {@link #unsubscribe} is called.\n */\n constructor(private initialTeardown?: () => void) {}\n\n /**\n * Disposes the resources held by the subscription. May, for instance, cancel\n * an ongoing Observable execution or cancel any other type of work that\n * started when the Subscription was created.\n * @return {void}\n */\n unsubscribe(): void {\n let errors: any[] | undefined;\n\n if (!this.closed) {\n this.closed = true;\n\n // Remove this from it's parents.\n const { _parentage } = this;\n if (_parentage) {\n this._parentage = null;\n if (Array.isArray(_parentage)) {\n for (const parent of _parentage) {\n parent.remove(this);\n }\n } else {\n _parentage.remove(this);\n }\n }\n\n const { initialTeardown: initialFinalizer } = this;\n if (isFunction(initialFinalizer)) {\n try {\n initialFinalizer();\n } catch (e) {\n errors = e instanceof UnsubscriptionError ? e.errors : [e];\n }\n }\n\n const { _finalizers } = this;\n if (_finalizers) {\n this._finalizers = null;\n for (const finalizer of _finalizers) {\n try {\n execFinalizer(finalizer);\n } catch (err) {\n errors = errors ?? [];\n if (err instanceof UnsubscriptionError) {\n errors = [...errors, ...err.errors];\n } else {\n errors.push(err);\n }\n }\n }\n }\n\n if (errors) {\n throw new UnsubscriptionError(errors);\n }\n }\n }\n\n /**\n * Adds a finalizer to this subscription, so that finalization will be unsubscribed/called\n * when this subscription is unsubscribed. If this subscription is already {@link #closed},\n * because it has already been unsubscribed, then whatever finalizer is passed to it\n * will automatically be executed (unless the finalizer itself is also a closed subscription).\n *\n * Closed Subscriptions cannot be added as finalizers to any subscription. Adding a closed\n * subscription to a any subscription will result in no operation. (A noop).\n *\n * Adding a subscription to itself, or adding `null` or `undefined` will not perform any\n * operation at all. (A noop).\n *\n * `Subscription` instances that are added to this instance will automatically remove themselves\n * if they are unsubscribed. Functions and {@link Unsubscribable} objects that you wish to remove\n * will need to be removed manually with {@link #remove}\n *\n * @param teardown The finalization logic to add to this subscription.\n */\n add(teardown: TeardownLogic): void {\n // Only add the finalizer if it's not undefined\n // and don't add a subscription to itself.\n if (teardown && teardown !== this) {\n if (this.closed) {\n // If this subscription is already closed,\n // execute whatever finalizer is handed to it automatically.\n execFinalizer(teardown);\n } else {\n if (teardown instanceof Subscription) {\n // We don't add closed subscriptions, and we don't add the same subscription\n // twice. Subscription unsubscribe is idempotent.\n if (teardown.closed || teardown._hasParent(this)) {\n return;\n }\n teardown._addParent(this);\n }\n (this._finalizers = this._finalizers ?? []).push(teardown);\n }\n }\n }\n\n /**\n * Checks to see if a this subscription already has a particular parent.\n * This will signal that this subscription has already been added to the parent in question.\n * @param parent the parent to check for\n */\n private _hasParent(parent: Subscription) {\n const { _parentage } = this;\n return _parentage === parent || (Array.isArray(_parentage) && _parentage.includes(parent));\n }\n\n /**\n * Adds a parent to this subscription so it can be removed from the parent if it\n * unsubscribes on it's own.\n *\n * NOTE: THIS ASSUMES THAT {@link _hasParent} HAS ALREADY BEEN CHECKED.\n * @param parent The parent subscription to add\n */\n private _addParent(parent: Subscription) {\n const { _parentage } = this;\n this._parentage = Array.isArray(_parentage) ? (_parentage.push(parent), _parentage) : _parentage ? [_parentage, parent] : parent;\n }\n\n /**\n * Called on a child when it is removed via {@link #remove}.\n * @param parent The parent to remove\n */\n private _removeParent(parent: Subscription) {\n const { _parentage } = this;\n if (_parentage === parent) {\n this._parentage = null;\n } else if (Array.isArray(_parentage)) {\n arrRemove(_parentage, parent);\n }\n }\n\n /**\n * Removes a finalizer from this subscription that was previously added with the {@link #add} method.\n *\n * Note that `Subscription` instances, when unsubscribed, will automatically remove themselves\n * from every other `Subscription` they have been added to. This means that using the `remove` method\n * is not a common thing and should be used thoughtfully.\n *\n * If you add the same finalizer instance of a function or an unsubscribable object to a `Subscription` instance\n * more than once, you will need to call `remove` the same number of times to remove all instances.\n *\n * All finalizer instances are removed to free up memory upon unsubscription.\n *\n * @param teardown The finalizer to remove from this subscription\n */\n remove(teardown: Exclude): void {\n const { _finalizers } = this;\n _finalizers && arrRemove(_finalizers, teardown);\n\n if (teardown instanceof Subscription) {\n teardown._removeParent(this);\n }\n }\n}\n\nexport const EMPTY_SUBSCRIPTION = Subscription.EMPTY;\n\nexport function isSubscription(value: any): value is Subscription {\n return (\n value instanceof Subscription ||\n (value && 'closed' in value && isFunction(value.remove) && isFunction(value.add) && isFunction(value.unsubscribe))\n );\n}\n\nfunction execFinalizer(finalizer: Unsubscribable | (() => void)) {\n if (isFunction(finalizer)) {\n finalizer();\n } else {\n finalizer.unsubscribe();\n }\n}\n", "import { Subscriber } from './Subscriber';\nimport { ObservableNotification } from './types';\n\n/**\n * The {@link GlobalConfig} object for RxJS. It is used to configure things\n * like how to react on unhandled errors.\n */\nexport const config: GlobalConfig = {\n onUnhandledError: null,\n onStoppedNotification: null,\n Promise: undefined,\n useDeprecatedSynchronousErrorHandling: false,\n useDeprecatedNextContext: false,\n};\n\n/**\n * The global configuration object for RxJS, used to configure things\n * like how to react on unhandled errors. Accessible via {@link config}\n * object.\n */\nexport interface GlobalConfig {\n /**\n * A registration point for unhandled errors from RxJS. These are errors that\n * cannot were not handled by consuming code in the usual subscription path. For\n * example, if you have this configured, and you subscribe to an observable without\n * providing an error handler, errors from that subscription will end up here. This\n * will _always_ be called asynchronously on another job in the runtime. This is because\n * we do not want errors thrown in this user-configured handler to interfere with the\n * behavior of the library.\n */\n onUnhandledError: ((err: any) => void) | null;\n\n /**\n * A registration point for notifications that cannot be sent to subscribers because they\n * have completed, errored or have been explicitly unsubscribed. By default, next, complete\n * and error notifications sent to stopped subscribers are noops. However, sometimes callers\n * might want a different behavior. For example, with sources that attempt to report errors\n * to stopped subscribers, a caller can configure RxJS to throw an unhandled error instead.\n * This will _always_ be called asynchronously on another job in the runtime. This is because\n * we do not want errors thrown in this user-configured handler to interfere with the\n * behavior of the library.\n */\n onStoppedNotification: ((notification: ObservableNotification, subscriber: Subscriber) => void) | null;\n\n /**\n * The promise constructor used by default for {@link Observable#toPromise toPromise} and {@link Observable#forEach forEach}\n * methods.\n *\n * @deprecated As of version 8, RxJS will no longer support this sort of injection of a\n * Promise constructor. If you need a Promise implementation other than native promises,\n * please polyfill/patch Promise as you see appropriate. Will be removed in v8.\n */\n Promise?: PromiseConstructorLike;\n\n /**\n * If true, turns on synchronous error rethrowing, which is a deprecated behavior\n * in v6 and higher. This behavior enables bad patterns like wrapping a subscribe\n * call in a try/catch block. It also enables producer interference, a nasty bug\n * where a multicast can be broken for all observers by a downstream consumer with\n * an unhandled error. DO NOT USE THIS FLAG UNLESS IT'S NEEDED TO BUY TIME\n * FOR MIGRATION REASONS.\n *\n * @deprecated As of version 8, RxJS will no longer support synchronous throwing\n * of unhandled errors. All errors will be thrown on a separate call stack to prevent bad\n * behaviors described above. Will be removed in v8.\n */\n useDeprecatedSynchronousErrorHandling: boolean;\n\n /**\n * If true, enables an as-of-yet undocumented feature from v5: The ability to access\n * `unsubscribe()` via `this` context in `next` functions created in observers passed\n * to `subscribe`.\n *\n * This is being removed because the performance was severely problematic, and it could also cause\n * issues when types other than POJOs are passed to subscribe as subscribers, as they will likely have\n * their `this` context overwritten.\n *\n * @deprecated As of version 8, RxJS will no longer support altering the\n * context of next functions provided as part of an observer to Subscribe. Instead,\n * you will have access to a subscription or a signal or token that will allow you to do things like\n * unsubscribe and test closed status. Will be removed in v8.\n */\n useDeprecatedNextContext: boolean;\n}\n", "import type { TimerHandle } from './timerHandle';\ntype SetTimeoutFunction = (handler: () => void, timeout?: number, ...args: any[]) => TimerHandle;\ntype ClearTimeoutFunction = (handle: TimerHandle) => void;\n\ninterface TimeoutProvider {\n setTimeout: SetTimeoutFunction;\n clearTimeout: ClearTimeoutFunction;\n delegate:\n | {\n setTimeout: SetTimeoutFunction;\n clearTimeout: ClearTimeoutFunction;\n }\n | undefined;\n}\n\nexport const timeoutProvider: TimeoutProvider = {\n // When accessing the delegate, use the variable rather than `this` so that\n // the functions can be called without being bound to the provider.\n setTimeout(handler: () => void, timeout?: number, ...args) {\n const { delegate } = timeoutProvider;\n if (delegate?.setTimeout) {\n return delegate.setTimeout(handler, timeout, ...args);\n }\n return setTimeout(handler, timeout, ...args);\n },\n clearTimeout(handle) {\n const { delegate } = timeoutProvider;\n return (delegate?.clearTimeout || clearTimeout)(handle as any);\n },\n delegate: undefined,\n};\n", "import { config } from '../config';\nimport { timeoutProvider } from '../scheduler/timeoutProvider';\n\n/**\n * Handles an error on another job either with the user-configured {@link onUnhandledError},\n * or by throwing it on that new job so it can be picked up by `window.onerror`, `process.on('error')`, etc.\n *\n * This should be called whenever there is an error that is out-of-band with the subscription\n * or when an error hits a terminal boundary of the subscription and no error handler was provided.\n *\n * @param err the error to report\n */\nexport function reportUnhandledError(err: any) {\n timeoutProvider.setTimeout(() => {\n const { onUnhandledError } = config;\n if (onUnhandledError) {\n // Execute the user-configured error handler.\n onUnhandledError(err);\n } else {\n // Throw so it is picked up by the runtime's uncaught error mechanism.\n throw err;\n }\n });\n}\n", "/* tslint:disable:no-empty */\nexport function noop() { }\n", "import { CompleteNotification, NextNotification, ErrorNotification } from './types';\n\n/**\n * A completion object optimized for memory use and created to be the\n * same \"shape\" as other notifications in v8.\n * @internal\n */\nexport const COMPLETE_NOTIFICATION = (() => createNotification('C', undefined, undefined) as CompleteNotification)();\n\n/**\n * Internal use only. Creates an optimized error notification that is the same \"shape\"\n * as other notifications.\n * @internal\n */\nexport function errorNotification(error: any): ErrorNotification {\n return createNotification('E', undefined, error) as any;\n}\n\n/**\n * Internal use only. Creates an optimized next notification that is the same \"shape\"\n * as other notifications.\n * @internal\n */\nexport function nextNotification(value: T) {\n return createNotification('N', value, undefined) as NextNotification;\n}\n\n/**\n * Ensures that all notifications created internally have the same \"shape\" in v8.\n *\n * TODO: This is only exported to support a crazy legacy test in `groupBy`.\n * @internal\n */\nexport function createNotification(kind: 'N' | 'E' | 'C', value: any, error: any) {\n return {\n kind,\n value,\n error,\n };\n}\n", "import { config } from '../config';\n\nlet context: { errorThrown: boolean; error: any } | null = null;\n\n/**\n * Handles dealing with errors for super-gross mode. Creates a context, in which\n * any synchronously thrown errors will be passed to {@link captureError}. Which\n * will record the error such that it will be rethrown after the call back is complete.\n * TODO: Remove in v8\n * @param cb An immediately executed function.\n */\nexport function errorContext(cb: () => void) {\n if (config.useDeprecatedSynchronousErrorHandling) {\n const isRoot = !context;\n if (isRoot) {\n context = { errorThrown: false, error: null };\n }\n cb();\n if (isRoot) {\n const { errorThrown, error } = context!;\n context = null;\n if (errorThrown) {\n throw error;\n }\n }\n } else {\n // This is the general non-deprecated path for everyone that\n // isn't crazy enough to use super-gross mode (useDeprecatedSynchronousErrorHandling)\n cb();\n }\n}\n\n/**\n * Captures errors only in super-gross mode.\n * @param err the error to capture\n */\nexport function captureError(err: any) {\n if (config.useDeprecatedSynchronousErrorHandling && context) {\n context.errorThrown = true;\n context.error = err;\n }\n}\n", "import { isFunction } from './util/isFunction';\nimport { Observer, ObservableNotification } from './types';\nimport { isSubscription, Subscription } from './Subscription';\nimport { config } from './config';\nimport { reportUnhandledError } from './util/reportUnhandledError';\nimport { noop } from './util/noop';\nimport { nextNotification, errorNotification, COMPLETE_NOTIFICATION } from './NotificationFactories';\nimport { timeoutProvider } from './scheduler/timeoutProvider';\nimport { captureError } from './util/errorContext';\n\n/**\n * Implements the {@link Observer} interface and extends the\n * {@link Subscription} class. While the {@link Observer} is the public API for\n * consuming the values of an {@link Observable}, all Observers get converted to\n * a Subscriber, in order to provide Subscription-like capabilities such as\n * `unsubscribe`. Subscriber is a common type in RxJS, and crucial for\n * implementing operators, but it is rarely used as a public API.\n *\n * @class Subscriber\n */\nexport class Subscriber extends Subscription implements Observer {\n /**\n * A static factory for a Subscriber, given a (potentially partial) definition\n * of an Observer.\n * @param next The `next` callback of an Observer.\n * @param error The `error` callback of an\n * Observer.\n * @param complete The `complete` callback of an\n * Observer.\n * @return A Subscriber wrapping the (partially defined)\n * Observer represented by the given arguments.\n * @nocollapse\n * @deprecated Do not use. Will be removed in v8. There is no replacement for this\n * method, and there is no reason to be creating instances of `Subscriber` directly.\n * If you have a specific use case, please file an issue.\n */\n static create(next?: (x?: T) => void, error?: (e?: any) => void, complete?: () => void): Subscriber {\n return new SafeSubscriber(next, error, complete);\n }\n\n /** @deprecated Internal implementation detail, do not use directly. Will be made internal in v8. */\n protected isStopped: boolean = false;\n /** @deprecated Internal implementation detail, do not use directly. Will be made internal in v8. */\n protected destination: Subscriber | Observer; // this `any` is the escape hatch to erase extra type param (e.g. R)\n\n /**\n * @deprecated Internal implementation detail, do not use directly. Will be made internal in v8.\n * There is no reason to directly create an instance of Subscriber. This type is exported for typings reasons.\n */\n constructor(destination?: Subscriber | Observer) {\n super();\n if (destination) {\n this.destination = destination;\n // Automatically chain subscriptions together here.\n // if destination is a Subscription, then it is a Subscriber.\n if (isSubscription(destination)) {\n destination.add(this);\n }\n } else {\n this.destination = EMPTY_OBSERVER;\n }\n }\n\n /**\n * The {@link Observer} callback to receive notifications of type `next` from\n * the Observable, with a value. The Observable may call this method 0 or more\n * times.\n * @param {T} [value] The `next` value.\n * @return {void}\n */\n next(value?: T): void {\n if (this.isStopped) {\n handleStoppedNotification(nextNotification(value), this);\n } else {\n this._next(value!);\n }\n }\n\n /**\n * The {@link Observer} callback to receive notifications of type `error` from\n * the Observable, with an attached `Error`. Notifies the Observer that\n * the Observable has experienced an error condition.\n * @param {any} [err] The `error` exception.\n * @return {void}\n */\n error(err?: any): void {\n if (this.isStopped) {\n handleStoppedNotification(errorNotification(err), this);\n } else {\n this.isStopped = true;\n this._error(err);\n }\n }\n\n /**\n * The {@link Observer} callback to receive a valueless notification of type\n * `complete` from the Observable. Notifies the Observer that the Observable\n * has finished sending push-based notifications.\n * @return {void}\n */\n complete(): void {\n if (this.isStopped) {\n handleStoppedNotification(COMPLETE_NOTIFICATION, this);\n } else {\n this.isStopped = true;\n this._complete();\n }\n }\n\n unsubscribe(): void {\n if (!this.closed) {\n this.isStopped = true;\n super.unsubscribe();\n this.destination = null!;\n }\n }\n\n protected _next(value: T): void {\n this.destination.next(value);\n }\n\n protected _error(err: any): void {\n try {\n this.destination.error(err);\n } finally {\n this.unsubscribe();\n }\n }\n\n protected _complete(): void {\n try {\n this.destination.complete();\n } finally {\n this.unsubscribe();\n }\n }\n}\n\n/**\n * This bind is captured here because we want to be able to have\n * compatibility with monoid libraries that tend to use a method named\n * `bind`. In particular, a library called Monio requires this.\n */\nconst _bind = Function.prototype.bind;\n\nfunction bind any>(fn: Fn, thisArg: any): Fn {\n return _bind.call(fn, thisArg);\n}\n\n/**\n * Internal optimization only, DO NOT EXPOSE.\n * @internal\n */\nclass ConsumerObserver implements Observer {\n constructor(private partialObserver: Partial>) {}\n\n next(value: T): void {\n const { partialObserver } = this;\n if (partialObserver.next) {\n try {\n partialObserver.next(value);\n } catch (error) {\n handleUnhandledError(error);\n }\n }\n }\n\n error(err: any): void {\n const { partialObserver } = this;\n if (partialObserver.error) {\n try {\n partialObserver.error(err);\n } catch (error) {\n handleUnhandledError(error);\n }\n } else {\n handleUnhandledError(err);\n }\n }\n\n complete(): void {\n const { partialObserver } = this;\n if (partialObserver.complete) {\n try {\n partialObserver.complete();\n } catch (error) {\n handleUnhandledError(error);\n }\n }\n }\n}\n\nexport class SafeSubscriber extends Subscriber {\n constructor(\n observerOrNext?: Partial> | ((value: T) => void) | null,\n error?: ((e?: any) => void) | null,\n complete?: (() => void) | null\n ) {\n super();\n\n let partialObserver: Partial>;\n if (isFunction(observerOrNext) || !observerOrNext) {\n // The first argument is a function, not an observer. The next\n // two arguments *could* be observers, or they could be empty.\n partialObserver = {\n next: (observerOrNext ?? undefined) as (((value: T) => void) | undefined),\n error: error ?? undefined,\n complete: complete ?? undefined,\n };\n } else {\n // The first argument is a partial observer.\n let context: any;\n if (this && config.useDeprecatedNextContext) {\n // This is a deprecated path that made `this.unsubscribe()` available in\n // next handler functions passed to subscribe. This only exists behind a flag\n // now, as it is *very* slow.\n context = Object.create(observerOrNext);\n context.unsubscribe = () => this.unsubscribe();\n partialObserver = {\n next: observerOrNext.next && bind(observerOrNext.next, context),\n error: observerOrNext.error && bind(observerOrNext.error, context),\n complete: observerOrNext.complete && bind(observerOrNext.complete, context),\n };\n } else {\n // The \"normal\" path. Just use the partial observer directly.\n partialObserver = observerOrNext;\n }\n }\n\n // Wrap the partial observer to ensure it's a full observer, and\n // make sure proper error handling is accounted for.\n this.destination = new ConsumerObserver(partialObserver);\n }\n}\n\nfunction handleUnhandledError(error: any) {\n if (config.useDeprecatedSynchronousErrorHandling) {\n captureError(error);\n } else {\n // Ideal path, we report this as an unhandled error,\n // which is thrown on a new call stack.\n reportUnhandledError(error);\n }\n}\n\n/**\n * An error handler used when no error handler was supplied\n * to the SafeSubscriber -- meaning no error handler was supplied\n * do the `subscribe` call on our observable.\n * @param err The error to handle\n */\nfunction defaultErrorHandler(err: any) {\n throw err;\n}\n\n/**\n * A handler for notifications that cannot be sent to a stopped subscriber.\n * @param notification The notification being sent\n * @param subscriber The stopped subscriber\n */\nfunction handleStoppedNotification(notification: ObservableNotification, subscriber: Subscriber) {\n const { onStoppedNotification } = config;\n onStoppedNotification && timeoutProvider.setTimeout(() => onStoppedNotification(notification, subscriber));\n}\n\n/**\n * The observer used as a stub for subscriptions where the user did not\n * pass any arguments to `subscribe`. Comes with the default error handling\n * behavior.\n */\nexport const EMPTY_OBSERVER: Readonly> & { closed: true } = {\n closed: true,\n next: noop,\n error: defaultErrorHandler,\n complete: noop,\n};\n", "/**\n * Symbol.observable or a string \"@@observable\". Used for interop\n *\n * @deprecated We will no longer be exporting this symbol in upcoming versions of RxJS.\n * Instead polyfill and use Symbol.observable directly *or* use https://www.npmjs.com/package/symbol-observable\n */\nexport const observable: string | symbol = (() => (typeof Symbol === 'function' && Symbol.observable) || '@@observable')();\n", "/**\n * This function takes one parameter and just returns it. Simply put,\n * this is like `(x: T): T => x`.\n *\n * ## Examples\n *\n * This is useful in some cases when using things like `mergeMap`\n *\n * ```ts\n * import { interval, take, map, range, mergeMap, identity } from 'rxjs';\n *\n * const source$ = interval(1000).pipe(take(5));\n *\n * const result$ = source$.pipe(\n * map(i => range(i)),\n * mergeMap(identity) // same as mergeMap(x => x)\n * );\n *\n * result$.subscribe({\n * next: console.log\n * });\n * ```\n *\n * Or when you want to selectively apply an operator\n *\n * ```ts\n * import { interval, take, identity } from 'rxjs';\n *\n * const shouldLimit = () => Math.random() < 0.5;\n *\n * const source$ = interval(1000);\n *\n * const result$ = source$.pipe(shouldLimit() ? take(5) : identity);\n *\n * result$.subscribe({\n * next: console.log\n * });\n * ```\n *\n * @param x Any value that is returned by this function\n * @returns The value passed as the first parameter to this function\n */\nexport function identity(x: T): T {\n return x;\n}\n", "import { identity } from './identity';\nimport { UnaryFunction } from '../types';\n\nexport function pipe(): typeof identity;\nexport function pipe(fn1: UnaryFunction): UnaryFunction;\nexport function pipe(fn1: UnaryFunction, fn2: UnaryFunction): UnaryFunction;\nexport function pipe(fn1: UnaryFunction, fn2: UnaryFunction, fn3: UnaryFunction): UnaryFunction;\nexport function pipe(\n fn1: UnaryFunction,\n fn2: UnaryFunction,\n fn3: UnaryFunction,\n fn4: UnaryFunction\n): UnaryFunction;\nexport function pipe(\n fn1: UnaryFunction,\n fn2: UnaryFunction,\n fn3: UnaryFunction,\n fn4: UnaryFunction,\n fn5: UnaryFunction\n): UnaryFunction;\nexport function pipe(\n fn1: UnaryFunction,\n fn2: UnaryFunction,\n fn3: UnaryFunction,\n fn4: UnaryFunction,\n fn5: UnaryFunction,\n fn6: UnaryFunction\n): UnaryFunction;\nexport function pipe(\n fn1: UnaryFunction,\n fn2: UnaryFunction,\n fn3: UnaryFunction,\n fn4: UnaryFunction,\n fn5: UnaryFunction,\n fn6: UnaryFunction,\n fn7: UnaryFunction\n): UnaryFunction;\nexport function pipe(\n fn1: UnaryFunction,\n fn2: UnaryFunction,\n fn3: UnaryFunction,\n fn4: UnaryFunction,\n fn5: UnaryFunction,\n fn6: UnaryFunction,\n fn7: UnaryFunction,\n fn8: UnaryFunction\n): UnaryFunction;\nexport function pipe(\n fn1: UnaryFunction,\n fn2: UnaryFunction,\n fn3: UnaryFunction,\n fn4: UnaryFunction,\n fn5: UnaryFunction,\n fn6: UnaryFunction,\n fn7: UnaryFunction,\n fn8: UnaryFunction,\n fn9: UnaryFunction\n): UnaryFunction;\nexport function pipe(\n fn1: UnaryFunction,\n fn2: UnaryFunction,\n fn3: UnaryFunction,\n fn4: UnaryFunction,\n fn5: UnaryFunction,\n fn6: UnaryFunction,\n fn7: UnaryFunction,\n fn8: UnaryFunction,\n fn9: UnaryFunction,\n ...fns: UnaryFunction[]\n): UnaryFunction;\n\n/**\n * pipe() can be called on one or more functions, each of which can take one argument (\"UnaryFunction\")\n * and uses it to return a value.\n * It returns a function that takes one argument, passes it to the first UnaryFunction, and then\n * passes the result to the next one, passes that result to the next one, and so on. \n */\nexport function pipe(...fns: Array>): UnaryFunction {\n return pipeFromArray(fns);\n}\n\n/** @internal */\nexport function pipeFromArray(fns: Array>): UnaryFunction {\n if (fns.length === 0) {\n return identity as UnaryFunction;\n }\n\n if (fns.length === 1) {\n return fns[0];\n }\n\n return function piped(input: T): R {\n return fns.reduce((prev: any, fn: UnaryFunction) => fn(prev), input as any);\n };\n}\n", "import { Operator } from './Operator';\nimport { SafeSubscriber, Subscriber } from './Subscriber';\nimport { isSubscription, Subscription } from './Subscription';\nimport { TeardownLogic, OperatorFunction, Subscribable, Observer } from './types';\nimport { observable as Symbol_observable } from './symbol/observable';\nimport { pipeFromArray } from './util/pipe';\nimport { config } from './config';\nimport { isFunction } from './util/isFunction';\nimport { errorContext } from './util/errorContext';\n\n/**\n * A representation of any set of values over any amount of time. This is the most basic building block\n * of RxJS.\n *\n * @class Observable\n */\nexport class Observable implements Subscribable {\n /**\n * @deprecated Internal implementation detail, do not use directly. Will be made internal in v8.\n */\n source: Observable | undefined;\n\n /**\n * @deprecated Internal implementation detail, do not use directly. Will be made internal in v8.\n */\n operator: Operator | undefined;\n\n /**\n * @constructor\n * @param {Function} subscribe the function that is called when the Observable is\n * initially subscribed to. This function is given a Subscriber, to which new values\n * can be `next`ed, or an `error` method can be called to raise an error, or\n * `complete` can be called to notify of a successful completion.\n */\n constructor(subscribe?: (this: Observable, subscriber: Subscriber) => TeardownLogic) {\n if (subscribe) {\n this._subscribe = subscribe;\n }\n }\n\n // HACK: Since TypeScript inherits static properties too, we have to\n // fight against TypeScript here so Subject can have a different static create signature\n /**\n * Creates a new Observable by calling the Observable constructor\n * @owner Observable\n * @method create\n * @param {Function} subscribe? the subscriber function to be passed to the Observable constructor\n * @return {Observable} a new observable\n * @nocollapse\n * @deprecated Use `new Observable()` instead. Will be removed in v8.\n */\n static create: (...args: any[]) => any = (subscribe?: (subscriber: Subscriber) => TeardownLogic) => {\n return new Observable(subscribe);\n };\n\n /**\n * Creates a new Observable, with this Observable instance as the source, and the passed\n * operator defined as the new observable's operator.\n * @method lift\n * @param operator the operator defining the operation to take on the observable\n * @return a new observable with the Operator applied\n * @deprecated Internal implementation detail, do not use directly. Will be made internal in v8.\n * If you have implemented an operator using `lift`, it is recommended that you create an\n * operator by simply returning `new Observable()` directly. See \"Creating new operators from\n * scratch\" section here: https://rxjs.dev/guide/operators\n */\n lift(operator?: Operator): Observable {\n const observable = new Observable();\n observable.source = this;\n observable.operator = operator;\n return observable;\n }\n\n subscribe(observerOrNext?: Partial> | ((value: T) => void)): Subscription;\n /** @deprecated Instead of passing separate callback arguments, use an observer argument. Signatures taking separate callback arguments will be removed in v8. Details: https://rxjs.dev/deprecations/subscribe-arguments */\n subscribe(next?: ((value: T) => void) | null, error?: ((error: any) => void) | null, complete?: (() => void) | null): Subscription;\n /**\n * Invokes an execution of an Observable and registers Observer handlers for notifications it will emit.\n *\n * Use it when you have all these Observables, but still nothing is happening.\n *\n * `subscribe` is not a regular operator, but a method that calls Observable's internal `subscribe` function. It\n * might be for example a function that you passed to Observable's constructor, but most of the time it is\n * a library implementation, which defines what will be emitted by an Observable, and when it be will emitted. This means\n * that calling `subscribe` is actually the moment when Observable starts its work, not when it is created, as it is often\n * the thought.\n *\n * Apart from starting the execution of an Observable, this method allows you to listen for values\n * that an Observable emits, as well as for when it completes or errors. You can achieve this in two\n * of the following ways.\n *\n * The first way is creating an object that implements {@link Observer} interface. It should have methods\n * defined by that interface, but note that it should be just a regular JavaScript object, which you can create\n * yourself in any way you want (ES6 class, classic function constructor, object literal etc.). In particular, do\n * not attempt to use any RxJS implementation details to create Observers - you don't need them. Remember also\n * that your object does not have to implement all methods. If you find yourself creating a method that doesn't\n * do anything, you can simply omit it. Note however, if the `error` method is not provided and an error happens,\n * it will be thrown asynchronously. Errors thrown asynchronously cannot be caught using `try`/`catch`. Instead,\n * use the {@link onUnhandledError} configuration option or use a runtime handler (like `window.onerror` or\n * `process.on('error)`) to be notified of unhandled errors. Because of this, it's recommended that you provide\n * an `error` method to avoid missing thrown errors.\n *\n * The second way is to give up on Observer object altogether and simply provide callback functions in place of its methods.\n * This means you can provide three functions as arguments to `subscribe`, where the first function is equivalent\n * of a `next` method, the second of an `error` method and the third of a `complete` method. Just as in case of an Observer,\n * if you do not need to listen for something, you can omit a function by passing `undefined` or `null`,\n * since `subscribe` recognizes these functions by where they were placed in function call. When it comes\n * to the `error` function, as with an Observer, if not provided, errors emitted by an Observable will be thrown asynchronously.\n *\n * You can, however, subscribe with no parameters at all. This may be the case where you're not interested in terminal events\n * and you also handled emissions internally by using operators (e.g. using `tap`).\n *\n * Whichever style of calling `subscribe` you use, in both cases it returns a Subscription object.\n * This object allows you to call `unsubscribe` on it, which in turn will stop the work that an Observable does and will clean\n * up all resources that an Observable used. Note that cancelling a subscription will not call `complete` callback\n * provided to `subscribe` function, which is reserved for a regular completion signal that comes from an Observable.\n *\n * Remember that callbacks provided to `subscribe` are not guaranteed to be called asynchronously.\n * It is an Observable itself that decides when these functions will be called. For example {@link of}\n * by default emits all its values synchronously. Always check documentation for how given Observable\n * will behave when subscribed and if its default behavior can be modified with a `scheduler`.\n *\n * #### Examples\n *\n * Subscribe with an {@link guide/observer Observer}\n *\n * ```ts\n * import { of } from 'rxjs';\n *\n * const sumObserver = {\n * sum: 0,\n * next(value) {\n * console.log('Adding: ' + value);\n * this.sum = this.sum + value;\n * },\n * error() {\n * // We actually could just remove this method,\n * // since we do not really care about errors right now.\n * },\n * complete() {\n * console.log('Sum equals: ' + this.sum);\n * }\n * };\n *\n * of(1, 2, 3) // Synchronously emits 1, 2, 3 and then completes.\n * .subscribe(sumObserver);\n *\n * // Logs:\n * // 'Adding: 1'\n * // 'Adding: 2'\n * // 'Adding: 3'\n * // 'Sum equals: 6'\n * ```\n *\n * Subscribe with functions ({@link deprecations/subscribe-arguments deprecated})\n *\n * ```ts\n * import { of } from 'rxjs'\n *\n * let sum = 0;\n *\n * of(1, 2, 3).subscribe(\n * value => {\n * console.log('Adding: ' + value);\n * sum = sum + value;\n * },\n * undefined,\n * () => console.log('Sum equals: ' + sum)\n * );\n *\n * // Logs:\n * // 'Adding: 1'\n * // 'Adding: 2'\n * // 'Adding: 3'\n * // 'Sum equals: 6'\n * ```\n *\n * Cancel a subscription\n *\n * ```ts\n * import { interval } from 'rxjs';\n *\n * const subscription = interval(1000).subscribe({\n * next(num) {\n * console.log(num)\n * },\n * complete() {\n * // Will not be called, even when cancelling subscription.\n * console.log('completed!');\n * }\n * });\n *\n * setTimeout(() => {\n * subscription.unsubscribe();\n * console.log('unsubscribed!');\n * }, 2500);\n *\n * // Logs:\n * // 0 after 1s\n * // 1 after 2s\n * // 'unsubscribed!' after 2.5s\n * ```\n *\n * @param {Observer|Function} observerOrNext (optional) Either an observer with methods to be called,\n * or the first of three possible handlers, which is the handler for each value emitted from the subscribed\n * Observable.\n * @param {Function} error (optional) A handler for a terminal event resulting from an error. If no error handler is provided,\n * the error will be thrown asynchronously as unhandled.\n * @param {Function} complete (optional) A handler for a terminal event resulting from successful completion.\n * @return {Subscription} a subscription reference to the registered handlers\n * @method subscribe\n */\n subscribe(\n observerOrNext?: Partial> | ((value: T) => void) | null,\n error?: ((error: any) => void) | null,\n complete?: (() => void) | null\n ): Subscription {\n const subscriber = isSubscriber(observerOrNext) ? observerOrNext : new SafeSubscriber(observerOrNext, error, complete);\n\n errorContext(() => {\n const { operator, source } = this;\n subscriber.add(\n operator\n ? // We're dealing with a subscription in the\n // operator chain to one of our lifted operators.\n operator.call(subscriber, source)\n : source\n ? // If `source` has a value, but `operator` does not, something that\n // had intimate knowledge of our API, like our `Subject`, must have\n // set it. We're going to just call `_subscribe` directly.\n this._subscribe(subscriber)\n : // In all other cases, we're likely wrapping a user-provided initializer\n // function, so we need to catch errors and handle them appropriately.\n this._trySubscribe(subscriber)\n );\n });\n\n return subscriber;\n }\n\n /** @internal */\n protected _trySubscribe(sink: Subscriber): TeardownLogic {\n try {\n return this._subscribe(sink);\n } catch (err) {\n // We don't need to return anything in this case,\n // because it's just going to try to `add()` to a subscription\n // above.\n sink.error(err);\n }\n }\n\n /**\n * Used as a NON-CANCELLABLE means of subscribing to an observable, for use with\n * APIs that expect promises, like `async/await`. You cannot unsubscribe from this.\n *\n * **WARNING**: Only use this with observables you *know* will complete. If the source\n * observable does not complete, you will end up with a promise that is hung up, and\n * potentially all of the state of an async function hanging out in memory. To avoid\n * this situation, look into adding something like {@link timeout}, {@link take},\n * {@link takeWhile}, or {@link takeUntil} amongst others.\n *\n * #### Example\n *\n * ```ts\n * import { interval, take } from 'rxjs';\n *\n * const source$ = interval(1000).pipe(take(4));\n *\n * async function getTotal() {\n * let total = 0;\n *\n * await source$.forEach(value => {\n * total += value;\n * console.log('observable -> ' + value);\n * });\n *\n * return total;\n * }\n *\n * getTotal().then(\n * total => console.log('Total: ' + total)\n * );\n *\n * // Expected:\n * // 'observable -> 0'\n * // 'observable -> 1'\n * // 'observable -> 2'\n * // 'observable -> 3'\n * // 'Total: 6'\n * ```\n *\n * @param next a handler for each value emitted by the observable\n * @return a promise that either resolves on observable completion or\n * rejects with the handled error\n */\n forEach(next: (value: T) => void): Promise;\n\n /**\n * @param next a handler for each value emitted by the observable\n * @param promiseCtor a constructor function used to instantiate the Promise\n * @return a promise that either resolves on observable completion or\n * rejects with the handled error\n * @deprecated Passing a Promise constructor will no longer be available\n * in upcoming versions of RxJS. This is because it adds weight to the library, for very\n * little benefit. If you need this functionality, it is recommended that you either\n * polyfill Promise, or you create an adapter to convert the returned native promise\n * to whatever promise implementation you wanted. Will be removed in v8.\n */\n forEach(next: (value: T) => void, promiseCtor: PromiseConstructorLike): Promise;\n\n forEach(next: (value: T) => void, promiseCtor?: PromiseConstructorLike): Promise {\n promiseCtor = getPromiseCtor(promiseCtor);\n\n return new promiseCtor((resolve, reject) => {\n const subscriber = new SafeSubscriber({\n next: (value) => {\n try {\n next(value);\n } catch (err) {\n reject(err);\n subscriber.unsubscribe();\n }\n },\n error: reject,\n complete: resolve,\n });\n this.subscribe(subscriber);\n }) as Promise;\n }\n\n /** @internal */\n protected _subscribe(subscriber: Subscriber): TeardownLogic {\n return this.source?.subscribe(subscriber);\n }\n\n /**\n * An interop point defined by the es7-observable spec https://github.com/zenparsing/es-observable\n * @method Symbol.observable\n * @return {Observable} this instance of the observable\n */\n [Symbol_observable]() {\n return this;\n }\n\n /* tslint:disable:max-line-length */\n pipe(): Observable;\n pipe(op1: OperatorFunction): Observable;\n pipe(op1: OperatorFunction, op2: OperatorFunction): Observable;\n pipe(op1: OperatorFunction, op2: OperatorFunction, op3: OperatorFunction): Observable;\n pipe(\n op1: OperatorFunction,\n op2: OperatorFunction,\n op3: OperatorFunction,\n op4: OperatorFunction\n ): Observable;\n pipe(\n op1: OperatorFunction,\n op2: OperatorFunction,\n op3: OperatorFunction,\n op4: OperatorFunction,\n op5: OperatorFunction\n ): Observable